Short Question
- What is the proper way to install
pip
,virtualenv
, anddistribute
?
Background
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
No more setuptools and easy_install
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
Glyph's Rebuke
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.
Back to the short question
So Glyph's response leads me to my original question:
- What is the proper way to install
pip
,virtualenv
, anddistribute
?
Best Answer
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:
Now you can use your "bootstrap" environment to create more:
Go nuts!
Note
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 justpython virtualenv.py path-to-bootstrap
orpython3 virtualenv.py path-to-bootstrap
.