2

I have a MacBook Pro that came pre-installed with python2.7. I later installed python3 and ipython notebook. I installed pip too to install packages, and am able to install packages and run program from python3. However, for another project I need to run code in python2.7, and I am not sure how to install it in python2.7 folder.

I tried using pip for installing packages to 2.7, but it kept giving error saying package already exists. When I check for version of python using --version, I see 2 pythons installed. However, when I check for pip and pip3, both seem to be in th same folder.

Any tips on how to install packages in python2.7, without making any changes to 3.3? I am using python3 and ipython notebooks for another project.

viveks-mbp:~ vivekyadav$ which pip
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip
viveks-mbp:~ vivekyadav$ which pip3
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip3

viveks-mbp:~ vivekyadav$ which python
/usr/bin/python
viveks-mbp:~ vivekyadav$ which python3
/Library/Frameworks/Python.framework/Versions/3.3/bin/python3
ibodi
  • 1,543
  • 3
  • 21
  • 40
  • 1
    http://stackoverflow.com/questions/32680081/importerror-after-successful-pip-installation – cel Feb 05 '16 at 19:07
  • Possible duplicate of [pip: dealing with multiple Python versions?](http://stackoverflow.com/questions/2812520/pip-dealing-with-multiple-python-versions), [how to pip install to specific version of python](http://stackoverflow.com/questions/10919569/how-to-pip-install-to-specific-version-of-python) – GingerPlusPlus Feb 05 '16 at 19:09
  • if you have the package downloaded... `python setup.py install --home="Path/to/python2.7/install"` should just install it to 2.7 – jalomas7 Feb 05 '16 at 19:14

1 Answers1

1

You can use the virtualenv to create a kind of sandbox.

$ virtualenv <work-directory>
$ source <work-directory>/bin/activate

The last command initiate your virtual environment, totally isolated from the system. So every pip command will install the package inside this directory.

But you have to run your application inside the virtual environment too.

Ismael Infante
  • 522
  • 4
  • 8