Install Pip script
Introducing a pure python means to install pip and it's requirements all in one go .
Installing pip on Windows is relatively straightforward, now, but still a tad bumpy. Basically it consists of
- Download distribute or setuptools
- Install it with
python distribute_setup.py
- Download the get-pip script
- Install with
python get-pip.py
(Aside: curiously the distribute docs say you can use pip to install distribute!)
On Windows this means installing wget
or curl
in
order to follow the install instructions as given, or pointing and clicking
your through click-this-url >> save as >> choose a spot >> open a python shell >> ...etc..
Easy, but boring and easy to make small mistakes which means repeating
all or part of the recipe.
So as part of my continuing quest to learn enough to be called a true
pythonista, I wrote a small script to do it all in one go, install-pip.py.
It is adapted from Fernando Macedo's
answer in How to install pip on windows?.
The seminal idea is it use urllib
to do the download, which
is included in Python's standard library -- isn't it just great to have
batteries included? (though it would begs the question of why there isn't
a python package installer battery included...)
The script does a bit more, but here's the essential idea:
sources = [
'http://python-distribute.org/distribute_setup.py',
'https://raw.github.com/pypa/pip/master/contrib/get-pip.py',
]
for src in sources:
f = urlopen(src).read()
try: exec(f)
except: pass
Passing on an exception instead of dealing with it isn't a great idea, maybe even a stupid one, but without it only the first file is executed. Comments, fixes, and enhancements are all welcome. :)
See https://gist.github.com/maphew/5393935
date: 2013-04-16, 14:22
tags: [python]
category: Python