How to install packages in different version of python?

I have a macbook pro that came pre-installed with python 2.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 python 3. However, for another project I need to run code in python 2.7, and I am not sure how to install it in python 2.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 python 2.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


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.

链接地址: http://www.djcxy.com/p/72010.html

上一篇: OSX El Capitan python安装加密失败

下一篇: 如何在不同版本的python中安装软件包?