Folks,
After building and deploying a package called myShtuff
to a local pypicloud server, I am able to install it into a separate virtual env.
Everything seems to work, except for the path of the executable...
(venv)[ec2-user@ip-10-0-1-118 ~]$ pip freeze
Fabric==1.10.1
boto==2.38.0
myShtuff==0.1
ecdsa==0.13
paramiko==1.15.2
pycrypto==2.6.1
wsgiref==0.1.2
If I try running the script directly, I get:
(venv)[ec2-user@ip-10-0-1-118 ~]$ myShtuff
-bash: myShtuff: command not found
However, I can run it via:
(venv)[ec2-user@ip-10-0-1-118 ~]$ python /home/ec2-user/venv/lib/python2.7/site-packages/myShtuff/myShtuff.py
..works
Am I making a mistake when building the package? Somewhere in setup.cfg or setup.py?
Thanks!!!
Go to PyPI and create an account. Run twine upload dist/* in the terminal/command line. Enter the account credentials you registered for on the actual PyPI. Then, run pip install [package_name] to install your package.
You need a __main__.py
in your package, and an entry point defined in setup.py.
See here and here but in short, your __main__.py
runs whatever your main functionality is when running your module using python -m
, and setuptools can make whatever arbitrary functions you want to run as scripts. You can do either or both. Your __main__.py
looks like:
from .stuff import my_main_func
if __name__ == "__main__":
my_main_func()
and in setup.py:
entry_points={
'console_scripts': [
'myShtuffscript = myShtuff.stuff:my_main_func'
]
Here, myShtuffscript
is whatever you want the executable to be called, myShtuff
the name of your package, stuff
the name of file in the package (myShtuff/stuff.py
), and my_main_func
the name of a function in that file.
You need to define entry_point
in your setup.py
in order to directly execute something from the command line:
entry_points={
'console_scripts': [
'cursive = cursive.tools.cmd:cursive_command',
],
},
More details can be found here.
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