0

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.

  1. 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
  1. 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?

2
  • 1
    Could you create a virtualenv and install stuff into that? Commented Jul 18, 2014 at 21:56
  • I'm a noob, so could you please write out exactly what I need to enter where? Thanks! Commented Jul 18, 2014 at 22:01

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

7 Comments

Am I supposed to copy the chunk of text directly into Terminal, or am I supposed to copy it into a text file and try to run that? The first approach is giving me a ton of errors.
Each line prefixed with $ is typed into the terminal, the rest is examples of what happens when you do that. This assumes you're using a proper shell (which terminal does).
I tried creating a shell script with the following: virtualenv limitedenv Using base prefix '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages' New python executable in limitedenv/bin/python2 Also creating executable in limitedenv/bin/python Installing setuptools, pip Unfortunately I got a whole bunch of errors when I tried to run the script, starting with: ERROR: The executable limitedenv/bin/python is not functioning ERROR: It thinks sys.prefix is u'/Users/***/Desktop' (should be u'/Users/***/Desktop/limitedenv')
Did you run source bin/activate? This makes the virtual environment the currently active environment. You can do each of these steps manually in the Terminal, instead of creating a shell script.
The limitedenv folder was successfully created, and contains the following folders: bin/, include/, and lib/ However, after cd'ed into limitedenv/, and typed in source bin/activate, I got the following:-bash: bin/activate: No such file or directory
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.