问题
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