如何将软件包pip安装到/ usr / local / bin?

时间:2019-05-21 16:55:15

标签: python pip

文件结构:

  • MYTOOL.sh
  • main.py
  • setup.py

我的目标是在用户键入$ 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个问题,但似乎没有答案。

0 个答案:

没有答案
相关问题