I creating an install script for my python project which installs all the external dependencies I need in order to run properly.
I want to create a system alias named myScript
which will be alias for path/to/script/run.py
so users could just run it by using myScript command
How can I do it?
If your project has a setup.py
script and you're installing your python packages, scripts, and dependencies using setuptools
(and you should be), you can use the entry_points
feature of setuptools
.
setup.py
from setuptools import setup
setup(
# other arguments here...
entry_points={
'console_scripts': [
'myScript = my_package.run:main',
],
},
)
Your project structure should look like this:
setup.py
/my_package
__init__.py
run.py
Your run.py
script should have a main()
function, which will get run when someone types myScript
at the command line. This works regardless of what shell they use or what platform you're on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With