Reputation: 5138
For work-related reasons, I'm trying to install Python 2.7.8 directly onto my machine (Mac OSX 10.9).
I am current running Python 2.7.6 in Enthought Canopy, and I really don't want to touch the existing libraries there.
My problem is that I'd like to use pip to install packages for the new instantiation of Python, but currently pip is bundled up with Enthought Canopy, so it only installs packages in the site-packages path for Enthought Canopy.
I first tried the following:
pip install --install-option="--prefix=$PREFIX_PATH/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages" scikit-learn
But got the following error:
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in ./Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages
Then, I tried to add the existing Enthought folder to the path for the newly installed Python 2.7.8, By entering the following line at the end of the .bash_profile:
PYTHONPATH=$PYTHONPATH:Users/***/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
This led to errors when trying to import some of the packages, probably for this reason: Cannot import Scikit-Learn
I would really prefer just to install a new version of scikit-learn in a separate folder. Anyone have any suggestions?
Upvotes: 0
Views: 610
Reputation: 52892
You can use virtualenv
to create a self-contained python environment that can be configured and used separately from your regular python installation.
Create the virtualenv (for oldish versions of virtualenv you'd want to include --no-site-packages
right after virtualenv
):
$ virtualenv limitedenv
Using base prefix '/usr/local/Cellar/python3/3.3.3/Frameworks/Python.framework/Versions/3.3'
New python executable in limitedenv/bin/python3
Also creating executable in limitedenv/bin/python
Installing setuptools, pip...done.
Move into the virtualenv and activate it:
$ cd limitedenv/
$ source bin/activate
(limitedenv)$
Install the packages you're after with pip as you'd do globally:
(limitedenv)$ pip install scikit-learn
Downloading/unpacking scikit-learn
Downloading scikit-learn-0.15.0.tar.gz (7.0MB): ...
scikit-learn
will now be installed just inside limitedenv
, and as long as you have that environment active, invoking python or pip will be like this is your very own, secluded Python installation.
You can exit from the virtual environment by calling deactivate
:
(limitedenv)$ deactivate
$
This allows you to have different versions of python by themselves, different versions of libraries pr. project and different configurations based on what your project requires. virtualenv
is a very useful tool!
Upvotes: 1