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)
Pip3 is the Python3 version of pip. If you use pip, then only the python2. 7 version will be installed. You have to use pip3 for it to be installed on Python3.
We can have both Python 2 and Python 3 installed on any Windows or Linux device. We can either create different environments on different IDEs to use the versions separately or use the following ways to run them using the command prompt.
To use pip, first install a custom version of Python 2. pip is then installed with it. You can then use the pip command to create a virtualenv and install modules.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With