Today’s tip is brought to you by the color green and the number g.
If you’re an industrious Python programmer, you probably use pip
and virtualenv
to install your packages in an isolated location, which is great, and good job to you. However, having to install Django, pandas and ipython every time you want to experiment with something is a bit tiresome, since they’re all big files and downloading them takes a while, plus what if you’re on a data-limited connection and bla bla bla.
Here’s a very easy way to both speed up your downloads and avoid having to do them in the first place: Just create a file called ~/.pip/pip.conf
and put the following lines in it (this assumes you use a *nix-based OS, if you’re using Windows, I respect your choice, but you’re on your own Pedro Cunha has posted instructions in the comments section):
[global]
# This is now deprecated. PyPI has upgraded to a CDN,
# and mirrors are deprecated. Just use the default,
# it's now much, much faster.
# index-url=http://c.pypi.python.org/simple
download-cache = ~/.cache/pip/
These are just pip configuration options specified in a file. The index-url
option uses one of the PyPI mirrors to download packages from, I use c
because it is closest to me and very fresh. You should visit the list above and pick a mirror that suits you.
The download-cache
option saves all downloaded packages in a local directory and reuses them whenever you need to install things. This greatly speeds up installations, as you don’t have to download the same package twice. This is only good if you use virtualenvs a lot, but I do, and it has sped up my installations tremendously.
Let me know if you have any other favorite configuration options or tips!