Distributing python scripts
Date: January 20th 2016
Last updated: January 22nd 2016
Distributing python code is an essential part of development. A tedious way of distribution is to simply host a set of un-compiled files on Github or Dropbox. This is what I have been doing up until now (I'm ashamed to say without using git). It has "worked" for me because I was the only intended user and my code has not been overly complicated.
Example of a single script:
#!/home/ray/anaconda2/bin/python # usually... #!/usr/bin/python print 'hello'
Run at command prompt:
Or change permissions and run without calling python:
chmod +x hello.py # run ./hello.py
Options for distributing a python package:
- Compressed archive files (zipped as .zip or .tar.gz)
- Self-unpacking executables (executable file: platform specific)
- Self-contained, no install required (also platform specific)
- Python eggs (not platform specific)
For compressed archive files, a package can be unpacked and installed using python. If a package was created using python distributions utilities (disutils), installation can be carried out using setup.py. This can be as simple as changing to the directory that contains setup.py and running:
python setup.py install
Python eggs are compressed files that contain python scripts along with metadata. The metadata helps with installation and distribution by doing things like specifying package dependencies, or including data files. A python egg always has the file extension .egg. If you put a python egg where python knows to look (Python sys.path) you can start using its packages without doing anything else.
Packages for generating python eggs: