vivek yadav
vivek yadav

Reputation: 21

How to install packages in different version of python?

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

Upvotes: 2

Views: 1606

Answers (1)

Ismael Infante
Ismael Infante

Reputation: 532

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.

Upvotes: 1

Related Questions