I'm on Mac OS X and I've heard that to avoid global installation of packages (using sudo) that might cause problems with the python files that OS X uses, the path to install python packages must be different than that of OS X.
Currently python executables are installed in :
/usr/local/bin/
Pip installs modules over here :
/usr/local/lib/python2.7/site-packages
Python is used from here :
/usr/local/bin/python
Are these paths safe?
If you are on OS X, you should also have Python in
/usr/bin
:If you are using
brew
, the firstpython
should be a symlink:If you are not using
brew
, you will have to explain to us how you installed a second version ofpython
.You should also have at least two
site-packages
:If you installed
python
usingbrew
, you should also havepip
:You should probably upgrade that to the latest
pip
:It should be safe to install
python
packages using/usr/local/bin/pip
because they will be installed in/usr/local/lib/python2.7/site-packages
. The/usr/local
path is specifically for local software. Also,brew
installs its files to/usr/local
, so if you are usingbrew
, you are already installing files there.I am not sure why some folks say not to install any packages globally. I have never seen a reference that explained why this was a bad idea. If multiple users need the same package, it makes more sense to install it globally.
When I first started using
virtualenv
, it did not always work the way I expected it to. I had a machine with multiple users that neededrequests
, and because of problems withvirtualenv
, I wound up installing it globally usingpip
.Both
virtualenv
andpip
have improved a lot since I first started using them and I can see how using them can prevent some problems. If you are developing new software that needs the latest version of a package,virtualenv
allows you to install the package without affecting the rest of the system. However, I still do not see why it is a bad idea to install packages globally.You shouldn't be mucking about with Python package paths, and you shouldn't be installing Python packages globally at all. Use a virtualenv for each project, and let pip install the libraries locally inside the virtualenv.
There are a number of options you can take, the easiest (as others have suggested) is
virtualenv
. Hopefully that's already installed if not, this is one of the few modules you should install globally. If you have Python 3.4+, you "should" havevenv
module (which is similar to virtualenv, but it's maintained by the Python team).python2
python3
You could install modules to the local user using
pip
, but I'm not sure how well this is supported these days though:You could also append directories to the
$PYTHONPATH
bash variable, but this should only be done as a last resort and under parental supervision :D. Try the other methods before this one.I suggest you to make use of virtual environments, you can learn more about them here: http://docs.python-guide.org/en/latest/dev/virtualenvs/
to sum up
$ virtualenv venv
$ source venv/bin/activate
$ pip install requests
$ deactivate