Thursday, June 30, 2011

The proper way to install pip, virtualenv, and distribute for Python

The key bit to realize is that "virtualenv" installs "pip" and "distribute", which are the latest and bestest packaging tools for Python.

(optional) add these to ~/.bashrc:
PIP_REQUIRE_VIRTUALENV=true
PIP_RESPECT_VIRTUALENV=true

1. install system-level virtualenv
sudo aptitude install virtualenv

2. use it to create a clean "distribution" centered around a private Python executable and your own packaged scripts

virtualenv --no-site-packages --distribute ENV

3. activate it for this shell

. ENV/bin/activate

This modifies the local PATH, so now "python" is your private one. Add/remove packages to your heart's content without messing with the system-global one.

which pip
 #  /home/johnm/work/ex-package/ENV/bin/pip

4. verify by installing a package from the internet

pip install coverage
python -c 'import coverage'

5. verify by installing a local package

pip -v install Mypackage-0.1dev.tar.gz
python -c 'import mypackage'

No comments:

Post a Comment