Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

running a python package after compiling and uploading to pypicloud server

Tags:

python

pypi

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!!!

like image 790
Cmag Avatar asked May 13 '15 03:05

Cmag


People also ask

Where do I upload Python packages?

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.


2 Answers

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.

like image 129
engineerC Avatar answered Sep 28 '22 03:09

engineerC


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.

like image 30
skyline75489 Avatar answered Sep 28 '22 02:09

skyline75489