How to install a Python package system-wide on Linux?

南楼画角 提交于 2019-12-24 20:16:15

问题


I often encounter some python packages (which I installed using pip) which can be accessed like a standalone binary on Terminal . Not just a python module .

I want to know the standard way to create a package which can be installed by $pip install mypackage ( or by $python setup.py install) and is also available like $mypackage from anywhere. I know that I can access the __main__.py file by $python -m mypackage . But I want my package to function just like any binary stored in /usr/bin .

I am not looking for any alias/path variable hack and don't want to create .deb/.rpm stuffs .

EDIT: I got help from commentbox . Eventually , setuptools already has the option . Setuptools Documention

entry_point parameter of setup() function does the trick .

setup(
    # other arguments here...
    entry_points={
        'console_scripts': [
            'foo = my_package.some_module:main_func',
            'bar = other_module:some_func',
        ],
        'gui_scripts': [
            'baz = my_package_gui:start_func',
        ]
    }

Here entry_point takes a dictionary whose value contains a list . Two CLI scripts named foo and bar are created which contains function main_func and some_func respectively from my_package.some_module and other_module . Gui scripts can also be created via this method .

来源:https://stackoverflow.com/questions/47869521/how-to-install-a-python-package-system-wide-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!