I can\'t seem to use sudo pip install correctly so that it installs into the following directory:
/Library/Frameworks/Python.framework/Versions/2.7/lib/pyth
Virtualenv is your friend
Even if you want to add a package to your primary install, it's still best to do it in a virtual environment first, to ensure compatibility with your other packages. However, if you get familiar with virtualenv, you'll probably find there's really no reason to install anything in your base install.
The pip
executable is actually a Python script.
By default it contains (on Linux):
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
__requires__ = 'pip==1.5.6'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
)
So if you got the same in MacOS, pip
would always use /usr/bin/python
.
But this is a default. You can still provide the version of python you want either by editing the file or by using python explicitly.
If which python
returns /usr/bin/python
then something went wrong when you installed your own version. If it is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
, you can directly call:
sudo python `which pip` install scikit-learn --upgrade
However, chances are high that it won't work. The reason is that sudo
is resetting all your environment variables. To make it work, the easiest would be to use:
sudo -E pip install scikit-learn --upgrade
or
sudo -E python `which pip` install scikit-learn --upgrade
depending on your setup.
pip
was not thought of as something that root
should execute. The actual best way to use it is to install a local, non-root, python version. You just have to make sure that you use it by default by setting up the correct environment variables (such as PATH
on Linux) and then install pip
without sudo
using that python version.
An even better way would be to setup virtualenv
s from your root install.
This way, you can install/update whatever you want without root privileges and never bother again about why sudo pip
is not working. You would also avoid to provide root privileges to whatever is on Pypi and that would warrant that you don't mix system libs with your own.
You Should uninstall the existed python,then download new version.