简体   繁体   中英

Simplest Way To Specify Python Version For Package Install?

I have python 2.7 & 3.5 on my system. When I use sudo, easy_install, or pip to install a package it installs to 2.7.

How do I tell pip, sudo, easy_install to install the package to 3.5?

Example: This installs pytest to 2.5

pip install -U pytest

What would be the equivalent to install to 3.5?

The simplest way to install any pip package with specifying version is:

For Python 2.7:

pip install <package_name>

For Python 3.x

pip3 install <package_name>

This works on all the platforms, be it Linux, Windows or Mac if you have pip package manager installed.

On Windows, use the py Python launcher in combination with the -m switch:

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

On Linux, Mac OS X, and other POSIX systems, use:

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

It seems you're trying to install packages using pip on mac. Since the default python version is 2.7 for mac therefore the default pip also installs to python 2.7. In order to install to a custom version you can specify it like this:

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

#ie
python3.5 -m pip install -U pytest 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM