pip
, virtualenv
, and distribute
?In my answer to SO question 4314376, I recommended using ez_setup
so that you could then install pip
and virtualenv
as follows:
curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install virtualenv
I originally pulled these instructions from Jesse Noller's blog post So you want to use Python on the Mac?. I like the idea of keeping a clean global site-packages directory, so the only other packages I install there are virtualenvwrapper
and distribute
. (I recently added distribute
to my toolbox because of this Python public service announcement. To install these two packages, I used:
sudo pip install virtualenvwrapper
curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
To really follow that Python public service announcement, on a fresh Python install, I would do the following:
curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
sudo pip install virtualenv
sudo pip install virtualenvwrapper
In a comment to my answer to SO question 4314376, SO user Glyph stated:
NO. NEVER EVER do
sudo python setup.py install
whatever. Write a ~/.pydistutils.cfg that puts your pip installation into ~/.local or something. Especially files namedez_setup.py
tend to suck down newer versions of things like setuptools and easy_install, which can potentially break other things on your operating system.
So Glyph's response leads me to my original question:
pip
, virtualenv
, and distribute
?You can do this without installing anything into python itself.
You don't need sudo or any privileges.
You don't need to edit any files.
Install virtualenv into a bootstrap virtual environment. Use the that virtual environment to create more. Since virtualenv ships with pip and distribute, you get everything from one install.
Here is an example in bash:
# Select current version of virtualenv:
VERSION=12.0.7
# Name your first "bootstrap" environment:
INITIAL_ENV=bootstrap
# Set to whatever python interpreter you want for your first environment:
PYTHON=$(which python)
URL_BASE=https://pypi.python.org/packages/source/v/virtualenv
# --- Real work starts here ---
curl -O $URL_BASE/virtualenv-$VERSION.tar.gz
tar xzf virtualenv-$VERSION.tar.gz
# Create the first "bootstrap" environment.
$PYTHON virtualenv-$VERSION/virtualenv.py $INITIAL_ENV
# Don't need this anymore.
rm -rf virtualenv-$VERSION
# Install virtualenv into the environment.
$INITIAL_ENV/bin/pip install virtualenv-$VERSION.tar.gz
Now you can use your "bootstrap" environment to create more:
# Create a second environment from the first:
$INITIAL_ENV/bin/virtualenv py-env1
# Create more:
$INITIAL_ENV/bin/virtualenv py-env2
Go nuts!
This assumes you are not using a really old version of virtualenv.
Old versions required the flags --no-site-packges
(and depending on the version of Python, --distribute
). Now you can create your bootstrap environment with just python virtualenv.py path-to-bootstrap
or python3 virtualenv.py path-to-bootstrap
.