在OSX上安装具有多个版本的python软件包 [英] Installing python packages with multiple versions on OSX

查看:66
本文介绍了在OSX上安装具有多个版本的python软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OSX 10.9.4上为python3.4安装一个软件包.如您所知,python随OSX一起提供,因此当我安装python3.4时,我很高兴发现它带有自己的pip版本,这会为其安装软件包(在具有多个python版本的mac上安装pip会导致它可以安装在系统的python2.7上.)

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.)

我以前曾尝试安装此软件包( https://pypi.python.org /pypi/chrome/0.0.1 )与我的第一个pip安装(与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.

我用python3.4的新pip关键字运行了安装(当它自己被调用时会弹出帮助页面,所以我知道它可以工作),它告诉我该软件包已安装并尝试更新.更新显示我已经拥有最新版本.所以我尝试仅从python3.4卸载它并重新安装无济于事,并且从python2.7卸载pip并仅在3.4版上重新安装时得到了相同的结果.

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.

我还在此处没有成功.

已解决:

虽然python确实有一个目录,它的名称与软件包使用的目录相同,但这不是正确的目录,对我而言,它位于库的子目录中.虽然文档说引用pip2将导致该软件包安装在python3.4上,但这是错误的.但是,引用pip3.4对我有用.

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.

推荐答案

我的建议是您开始使用virtualenv.

My suggestion is that you start using virtualenv.

假设您已经安装了3.4,那么您还应该拥有pyvenv.至于pip和3.4,应该已经安装了.

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

以3.4版为例,创建您自己的虚拟环境并激活它:

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

对于2.7版,请先安装virtualenv,然后创建自己的虚拟环境并激活它.确保setuptools和pip已更新:

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

这篇关于在OSX上安装具有多个版本的python软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆