I wrote a command-line app using python. the problem is I want the to user can use the command globally after installed the command-line . I wrote the command-line, I published the package but I don't know how to make this package globally available for users as system commands.
Example :
pip install forosi
and after that user can globally run this command from everywhere they want . like :
forosi help
I'm going to assume you have the main file you are supposed to run in src/forosi.py
in your package directory, but you should be able to adapt this if it's different.
First, you want to rename the script to forosi
, without the .py
extension.
Second, at the top of the file (now called forosi
) add the following:
#!/usr/bin/env python3
... rest of file...
setup.py
for the package, you need to use the scripts
option.setuptools.setup(
...
scripts=['src/forosi'],
...
)
This is the method that required minimal refactoring of your code. If you happen to have a main()
function in one of your python files which is the entrypoint of the script, you can just add the following into your setup.py instead of the above:
setup(
...
entry_points = {
'console_scripts': ['src.forosi:main'],
}
...
)
In either case, to build the package locally, run
python3 setup.py bdist_wheel
This will create a wheel file in the dist/
directory called package_name-version-<info>-.whl
. This is the official distribution for pypi packages.
To install this package, run:
pip3 install dist/package_name-version-<info>-.whl
or if you only have one version in the dist folder, just
pip3 install dist/*
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments