Python usage notes/Packaging software

From Helpful
Jump to: navigation, search
Various things have their own pages, see Category:Python. Some of the pages that collect various practical notes include:


Distributing, and distutils: http://docs.python.org/dist/dist.html



Notes on eggs

Eggs let you package code for running and installing . They are archives with code and some metadata.


When you have a system-wide package/software managing software, you should always look to that first, as as you will benefit from its versioning, dependencies, and automatic updates.

This makes eggs mainly useful for things that probably won't make it into packages any time soon. It does save a whole bunch of install work, after all.


Installing eggs, easy_install, pip

When you give easy_install a name it will search pipy for a match, e.g.

easy_install networkx

When you give easy_install an egg, it will install it, e.g.

easy_install networkx-0.33-py2.4.egg

...can be useful if it's not on pipy or you want a specific version.


pip is an easy_install replacement.

It's a little cleverer than easy_install, and has a few more features, like uninstalling, and cooperating with virtualenv.

One feature it misses is egg installation.



Importing

This article/section is a stub — probably a pile of half-sorted notes, is not well-checked so may have incorrect bits. (Feel free to ignore, fix, or tell me)

Importing from an .egg is possible, and may be handy for admin-restricted / virtualenv setups. You'll probably only want to do so if there are no non-.py files that you may need to get to, though (presumably because that's the only thing that the importer deals with(verify)).

This is apparently often done with a supporting:

from pkg_resources import require
require("FooBar>=1.2")

This will look around your sys.path, and end up prepending a path to an .egg file to sys.path, which import can handle.


Creating eggs

See also



On freezing your apps

Freezing means packaging your code in an executable way -- i.e. with the python interpreter and all external modules.

This does create somewhat large executables (as it amounts to static linking), but the self-containedness is nice for distributing software.


To do this yourself, you can read things like https://docs.python.org/2/faq/windows.html#how-can-i-embed-python-into-a-windows-application


It's easier to use other people's tools.

Options I've tried:

  • cx_freeze
lin, win, osx
http://cx-freeze.sourceforge.net/
  • PyInstaller
lin, win, osx
can pack into single file
http://pyinstaller.python-hosting.com/
See also http://bytes.com/forum/thread579554.html for some get-started introduction

Untried:

lin, win, osx
  • py2exe [2] (a distutils extension)
windows (only)
can pack into single file
inactive project now?
  • Python's freeze.py (*nix) (I don't seem to have it, though)
mac OSX (only)
  • Gordon McMillan's Installer (discontinued, developed on into PyInstaller)


See also:


TODO: read:



Semi-sorted

https://packaging.python.org/en/latest/current.html


https://packaging.python.org/en/latest/projects.html