Is there any way to make pip
play well with multiple versions of Python? For example, I want to use pip
to explicitly install things to either my s
Most of the answers here address the issue but I want to add something what was continually confusing me with regard to creating an alternate installation of python in the /usr/local
on CentOS 7. When I installed there, it appeared like pip was working since I could use pip2.7 install
and it would install modules. However, what I couldn't figure out was why my newly installed version of python wasn't seeing what I was installing.
It turns out in CentOS 7 that there is already a python2.7 and a pip2.7 in the /usr/bin
folder. To install pip for your new python distribution, you need to specifically tell sudo to go to /usr/local/bin
sudo /usr/local/bin/python2.7 -m ensurepip
This should get pip2.7 installed in your /usr/local/bin
folder along with your version of python. The trick is that when you want to install modules, you either need to modify the sudo $PATH
variable to include /usr/local/bin
or you need to execute
sudo /usr/local/bin/pip2.7 install <module>
if you want to install a new module. It took me forever to remember that sudo
wasn't immediately seeing /usr/local/bin
.
Installation of multiple versions of Python and respective Packages.
Python version on the same windows machine : 2.7 , 3.4 and 3.6
Installation of all 3 versions of Python :
PATH for all 3 versions of Python :
Renaming the executables for versions :
Checked for the command prompt with all versions :
Installing the packages separately for each version
for example, if you set other versions (e.g. 3.5) as default and want to install pip for python 2.7:
You can go to for example C:\Python2.7\Scripts and then run cmd from that path. After that you can run pip2.7 install yourpackage...
That will install package for that version of Python.
If you have both python3.6
and python3.7
installed and want to use pip
with python3.7
by default, here's what you should do:
First make sure you have pip
installed for python3.7
python3.7 -m pip install -U pip
Now pip3.7
must be available, so we edit .bashrc
nano ~/.bashrc
adding the following line to it
alias pip=pip3.7
In order for the changes to take effect type in the shell:
source ~/.bashrc
Now if you type:
pip --version
you should get:
pip 20.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)
which means, if you use, for example:
pip install <package>
it would install the <package>
for python3.7