'Can pip (python2) and pip3 (python3) coexist?
I always thought that pip was for Python 2 and pip3 was for Python 3. To install the different versions of pip I have done the following:
sudo apt-get install python-pip
sudo apt-get install python3-pip
then I get the following as one would expect:
$ pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
Those are old versions, though, so I do the following:
$ sudo pip install pip --upgrade
and I get this:
$ pip --version
pip 19.0.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
and when I do a pip3 install for some package, I get the following message:
You are using pip version 8.1.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Well, I already ran that, so I try this:
$ sudo pip3 install pip --upgrade
Installing collected packages: pip
Found existing installation: pip 8.1.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-19.0.3
But now I get this:
$ pip --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
Is that correct? Does this matter? Does a pip version from Python 3.5 work for installing Python 2 packages?
UPDATE
Based on the answer provided by @furas, these are all the commands I run to get updated versions of pip and pip3 installed correctly:
sudo apt-get install python-pip --yes
sudo apt-get install python3-pip --yes
sudo python3 -m pip install pip --upgrade
sudo python -m pip install pip --upgrade --force # this line fixes the pip install to point to the python2 version instead of the python3 version
and that yields the following:
$ pip --version
pip 19.0.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
$ pip3 --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
Solution 1:[1]
Every Python should have own pip
because every Python may use different version of the same module and every Python installs modules in different folder.
You can use Python2
to reinstall module pip
for Python2
and it should create file with correct name pip
python -m pip install -U --force pip
You should also have pip
, pip2
, pip2.7
, pip3
, pip3.5
.
You can even have pip3.6
, pip3.7
at the same time.
If you write in console pip
and press tab
and it should show you all programs which start with word pip
You can find full path for pip
with
which pip
and you can open it in text editor to see if it is python's script.
Different pip
have different first line - ie. #!/usr/bin/python
or #!/usr/bin/python3.5
.
Rest code should be the same for all versions.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |