Nate Gardner Nate Gardner - 1 month ago 12
Python Question

Python on Windows: Which pip

I have different Python environments installed in different directories in Windows. How can I ensure I am using the pip for one particular version of Python?

Unfortunately, due to the groups I work with using a variety of Python flavors, I need all of the Python installations I have. I'm finding it very difficult, however, to use a version of pip that's not in my PATH.

Answer

I work with multiple Python installations, all of them in my PATH. A good way to manage this is to rename (or copy) the python.exe and pip.exe executables such that they describe the environment.

For example, for Python 3.5, my python executable is named python35.exe and the pip executable is pip35.exe For Python 2.7 The executable name is python27.exe and the pip executable is pip27.exe

When you install using the Windows installer from Python.org, PIP actually ships with a similar naming convention by default pip2.7.exe for Python 2.7 or pip3.5.exe for Python 3.5

I follow the same scheme for the various installations I have. If I want to install a package in Python 3.5 I run pip35 install <package>

You can also use the full path to the Python or pip executable and use pip that way. IE

C:\Python35\python.exe -m pip install <package>
#or
C:\Python35\Scripts\pip.exe install <package>

Another method of installing via pip is in a script/shell that you call using the appropriate version of Python.

import pip
pip.main(["install", "MyPackage"])
Comments