Python trick: installing packages

The standard installation procedure for packages built with distutils is python setup.py install. If you want to install in a nonstandard directory, add something like --prefix=/Users/vallis/…. But then the path to the library needs to be added to PYTHONPATH (colon separated), or the library won't be accessible to import without changing sys.path.

Python eggs are a nice innovation that can simplify installs involving C extensions. After installing easy_install and setting up a ~/.pydistutils.cfg specifying something like

[install]
install_lib = ~/lib/python2.4/site-packages
install_scripts = ~/bin

you simply need to run easy_install on the egg (or the tar.gz, or the package name… the tool is a veritable Swiss army knife).

By the way, a good install_lib location on OS X is ~/Library/Python/$py_version_short/site-packages, since Python will then recognize .pth files (which does not happen elsewhere)…

Note that the location specified in ~/.pydistutils.cfg may override other install locations given as --prefix parameters to setup.py. You're warned!

May 24, 2007

pythoninstall (/progtricks)
2007-05-24, 15:19 [edit]


  Login:   Password:   [rss] [cc] [w3] [css]

© M. Vallisneri 2012 — last modified on 2010/01/29

Tantum in modicis, quantum in maximis