文件结构:
我的目标是在用户键入$ MYTOOL
时使MYTOOL.sh运行。
在我的setup.py
文件中,我有以下内容:
class PostInstallCommand(install):
def run(self):
subprocess.call("echo source " + getSetuptoolsScriptDir() + "/MYTOOL.sh > /usr/local/bin/MYTOOL && chmod +x /usr/local/bin/MYTOOL", shell=True)
install.run(self)
def getSetuptoolsScriptDir():
dist = Distribution({'cmdclass': {'install': OnlyGetScriptPath}})
dist.dry_run = True
dist.parse_config_files()
command = dist.get_command_obj('install')
command.ensure_finalized()
command.run()
return dist.install_scripts
setuptools.setup(
# ... other settings ...
scripts=['MYTOOL.sh'],
cmdclass={
'install': PostInstallCommand,
}
)
MYTOOL.sh:
#!/bin/bash
PYTHON_VERSION=$(python -c 'import sys; print(".".join(map(str, sys.version_info[0:1])))')
if [ $PYTHON_VERSION -eq 3 ]
then
python main.py "$@"
else
python3 main.py "$@"
fi
PS:
我确实找到了this个问题,但似乎没有答案。