Skip to content Skip to sidebar Skip to footer

Making A Python Package Behave As A Native Cli App

I have a python package which I can use on the command line as python -m pkgname [args] I want to give it native-like behaviour (on linux) pkgname [args] how do I do this?

Solution 1:

Use a shebang.

Maybe something like putting this in the first line of the script:

#!/usr/bin/env python

Also you'll have to make it executable with chmod +x pkgname.py and make it available to the path.

Solution 2:

You can use shebang line by adding #!/usr/bin/python at the leading of your pack file ! then make your pack executable by run chmod +x pkgname.py in your terminal !

also as an alternative answer you can use alias :

alias pkgname="python -m pkgname"

Solution 3:

$ sudo chmod a+x pkname.py$ ln -s $(pwd)/pkgname.py /usr/bin/pkgname

this really has nothing to do with python (the first line makes it executable... the second line maps it to a place on your path

make sure the first line of pkname.py is

#!/usr/bin/env python

Solution 4:

You can write a setup.py script that will install the package. Once you've written setup.py you can install the package locally

python setup.py install

or build packages in a zillion ways (well, a few less than a zillion) that you copy to the machines you want. The current packaging craze is python + pip + wheels, so

python setup.py bdist_wheel 

Creates a file whose name encodes several details, look in dist/*.whl to find out what it is. Then on the target machine

pip intall path/to/the/crazily-named.whl

Post a Comment for "Making A Python Package Behave As A Native Cli App"