Skip to content

Instantly share code, notes, and snippets.

@lonsty
Created December 26, 2020 13:03
Show Gist options
  • Save lonsty/51db07922592dce1f9e89f8d9d644368 to your computer and use it in GitHub Desktop.
Save lonsty/51db07922592dce1f9e89f8d9d644368 to your computer and use it in GitHub Desktop.
Remove broken bin files
#!/usr/bin/env python3.7
# @Author: eilianxiao
# @Date: Dec 26 19:35 2020
"""删除找不到 Python 解释器的执行文件"""
import os
import subprocess
BIN_DIR = '/usr/local/bin'
found = subprocess.run(f'find {BIN_DIR} -type f', shell=True, stdout=subprocess.PIPE)
bin_files = found.stdout.decode().split('\n')
for bin in bin_files:
result = subprocess.run(f'{bin} --help', shell=True, capture_output=True)
err = result.stderr.decode()
if '/usr/local/opt/[email protected]/bin/python3.9: bad interpreter: No such file or directory' in err:
print(exec, err.split('\n')[0])
os.remove(bin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment