2

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?

1
  • There are different versions of pip for python u can use pip for python2 and pip3 for python3 Commented Feb 28, 2017 at 15:45

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.