Installing python packages with multiple versions

2019-02-20 00:57发布

I am attempting to install a package for python3.4 on Mac OSX 10.9.4. As you know, python ships with OSX, so when I installed python3.4 I was happy to find that it came with its own version of pip, that would install packages to it (installing pip on a mac with multiple versions of python will cause it to install on the system's python2.7.)

I had previously tried installing this package (https://pypi.python.org/pypi/chrome/0.0.1) with my first installation of pip (the one tied to python2.7) and found that it successfully installed on that version, but not on any others.

I ran an install with the new pip keyword for python3.4 (which when called by itself spits out the help page so i know it works) and it told me that the package was already installed and to try updating. The update revealed that I already had the most recent version. so I tried uninstalling it from just the python3.4 and reinstalling to no avail, and got the same results when uninstalling pip from python2.7 and reinstalling only on version 3.4.

I know that's a bit hard to follow but hopefully that makes sense.

I also reviewed the content here with no success.

RESOLVED:

while python did have a directory named the same as a directory it uses with packages, this was not the correct directory, for me it was in a subdirectory of library. while documentation said that referencing pip2 would cause the package to install on python3.4, this was false. however, referencing pip3.4 worked for me.

1条回答
【Aperson】
2楼-- · 2019-02-20 01:28

My suggestion is that you start using virtualenv.

Assuming you have 3.4 installed, then you should also have pyvenv. As for pip and 3.4, it should already be installed.

Using for example version 3.4 create your own virtual environment and activate it:

$ mkdir ~/venv
$ pyvenv-3.4 ~/venv/py34
$ source ~/venv/py34/bin/activate
$ deactive                     # does what is says...
$ source ~/venv/py34/bin/activate
$ pip install ...  # whatever package you need

With version 2.7 first install virtualenv and then create your own virtual environment and activate it. Make sure that setuptools and pip are updated:

$ virtualenv-2.7 ~/venv/venv27
$ . ~/venv/venv27/bin/activate
$ pip install -U setuptools
$ pip install -U pip
$ pip install ...  # whatever package you need
查看更多
登录 后发表回答