2017-02-28 240 views
1

我有我的系統上的Python 2.7 & 3.5。當我使用sudo,easy_install或pip安裝它安裝到2.7的包時。爲包安裝指定Python版本的最簡單方法?

我如何告訴點子,須藤,使用easy_install的包安裝到3.5?

舉例: 這將安裝pytest 2.5

pip install -U pytest 

什麼是要安裝到3.5當量?

+0

python有不同的版本,你可以使用'pip'作爲python2和'pip3' for python3 –

回答

2

與指定版本安裝任何PIP包的最簡單方法錫永是:

對於Python 2.7:

pip install <package_name> 

對於Python 3.x的

pip3 install <package_name> 

這適用於所有的平臺,是它的Linux,Windows或Mac,如果你有點子安裝包管理器。

0

在Windows上,使用py Python的發射器結合的-m開關:

ES:

py -2 -m pip install SomePackage # default Python 2 

py -2.7 -m pip install SomePackage # specifically Python 2.7 

py -3 -m pip install SomePackage # default Python 3 

py -3.4 -m pip install SomePackage # specifically Python 3.4 

在Linux,Mac OS X和其他POSIX系統,使用:

python2 -m pip install SomePackage # default Python 2 

python2.7 -m pip install SomePackage # specifically Python 2.7 

python3 -m pip install SomePackage # default Python 3 

python3.4 -m pip install SomePackage # specifically Python 3.4 
0

看來你要安裝在Mac上使用PIP封裝。由於默認的python版本是2.7 for mac,所以默認的pip也會安裝到python 2.7。爲了安裝到自定義版本,你可以這樣指定:

python3 -m pip install package 
#or 
python3.5 -m pip install package 

#ie 
python3.5 -m pip install -U pytest 
相關問題