pip or pip3 to install packages for Python 3?
Solution 1
Your pip
is a soft link to the same executable file path with pip3
.
you can use the commands below to check where your pip
and pip3
real paths are:
$ ls -l `which pip`
$ ls -l `which pip3`
You may also use the commands below to know more details:
$ pip show pip
$ pip3 show pip
When we install different versions of python, we may create such soft links to
- set default pip to some version.
- make different links for different versions.
It is the same situation with python
, python2
, python3
More information below if you're interested in how it happens in different cases:
Solution 2
If you had python 2.x and then installed python3, your pip will be pointing to pip3.
you can verify that by typing pip --version
which would be the same as pip3 --version
.
On your system you have now pip, pip2 and pip3.
If you want you can change pip to point to pip2 instead of pip3.
Solution 3
When you install python3
, pip3
gets installed. And if you don't have another python installation(like python2.7) then a link is created which points pip
to pip3
.
So pip
is a link to to pip3
if there is no other version of python installed(other than python3).
pip
generally points to the first installation.
Solution 4
By illustration:
pip --version
pip 19.0.3 from /usr/lib/python3.7/site-packages/pip (python 3.7)
pip3 --version
pip 19.0.3 from /usr/lib/python3.7/site-packages/pip (python 3.7)
python --version
Python 3.7.3
which python
/usr/bin/python
ls -l '/usr/bin/python'
lrwxrwxrwx 1 root root 7 Mar 26 14:43 /usr/bin/python -> python3
which python3
/usr/bin/python3
ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Mar 26 14:43 /usr/bin/python3 -> python3.7
ls -l /usr/bin/python3.7
-rwxr-xr-x 2 root root 14120 Mar 26 14:43 /usr/bin/python3.7
Thus, my in my default system python (Python 3.7.3), pip
is pip3
.
Solution 5
I think pip
, pip2
and pip3
are not soft links to the same executable file path. Note these commands and results in my Linux terminal:
mrz@mrz-pc ~ $ ls -l `which pip`
-rwxr-xr-x 1 root root 292 Nov 10 2016 /usr/bin/pip
mrz@mrz-pc ~ $ ls -l `which pip2`
-rwxr-xr-x 1 root root 283 Nov 10 2016 /usr/bin/pip2
mrz@mrz-pc ~ $ ls -l `which pip3`
-rwxr-xr-x 1 root root 293 Nov 10 2016 /usr/bin/pip3
mrz@mrz-pc ~ $ pip -V
pip 9.0.1 from /home/mrz/.local/lib/python2.7/site-packages (python 2.7)
mrz@mrz-pc ~ $ pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
mrz@mrz-pc ~ $ pip3 -V
pip 9.0.1 from /home/mrz/.local/lib/python3.5/site-packages (python 3.5)
As you see they exist in different paths.
pip3 always operates on the Python3 environment only, as pip2 does with Python2. pip operates in whichever environment is appropriate to the context. For example, if you are in a Python3 venv, pip will operate on the Python3 environment.
Related videos on Youtube
Ammar Alyousfi
Updated on March 22, 2022Comments
-
Ammar Alyousfi about 2 years
I have a Macbook with OS X El Captain. I think that Python 2.7 comes preinstalled on it. However, I installed Python 3.5 too. When I started using Python 3, I read that if I want to install a package, I should type:
pip3 install some_package
Anyway, now when I use
pip install some_package
I get
some_package
installed for Python 3. I mean I can import it and use it without problems. Moreover, when I type justpip3
in the Terminal. I got this message about the usage:Usage: pip <command> [options]
which is the same message I get when I type just
pip
.Does it mean that in previous versions, things were different, and now
pip
andpip3
can be used interchangeably? If so, and for the sake of argument, how can I install packages for Python 2 instead of Python 3? -
Luke Baumann over 6 yearsI would say it's a little misleading to say that pip is linked to whatever environment is appropriate for the context. In the case of venv the pip executable is specific to the venv and not the system. Unless you installed multiple versions of python in the same venv I can't see this problem arising there. When not using a venv, the version of pip used is sometimes unintuitive and depends on the configuration of your system (often it's determined by which version of python was installed first, as others have said) . But Pip doesn't have any intelligence it uses to select a version dynamically
-
ahnbizcad over 6 yearshow do you change that
-
apadana over 6 years@ahnbizcad The easiest way is to define an alias like this: alias pip="pip3"
-
Kevin Danikowski about 6 yearsI did this, but my pip3 was v9 when pip was v10, so I typed
pip3 install --upgrade pip
and it made both v10 -
Torsten Bronger over 5 yearsI think this is wrong. My pip3 also calls itself just pip in its help output, still, plain pip installs Python 2 packages on my system. I think stackoverflow.com/a/40832677/188108 is correct, at least it agrees with my observations.
-
Torsten Bronger over 5 yearsThis answer is wrong. pip will not point to pip3. pip will install Python 2 packages, and pip3 will install Python 3 packages. Tested on Lubuntu 18.10.
-
apadana over 5 years@TorstenBronger what was the order of python installations in your environment?
-
Torsten Bronger over 5 yearsThis is difficult to say because both versions are pre-installed.
-
Torsten Bronger over 5 yearsEverybody can check this easily:
docker run -ti ubuntu bash
, install python-pip, then python3-pip, then typepip install pyvisa
, which installs PyVISA only for Python2. -
CSJ over 5 yearsit changes on what environment and how you install python, this answer is to give clue how to know pip works, and to answer the questioner's situation. if it not same on your system, you still can use the same way to find out why. not mean it is wrong answer.
-
Torsten Bronger over 5 yearsI doubt that. I have no Mac but on the Ubuntu flavours I tested, pip variants are not symlinks. Instead, they are tiny Python scripts that differ only in the shebang line.
-
CSJ over 5 yearsyeah, that's what I mean it changes on environment and the way you install python(brew, apt, pyenv, compile manually, etc) and to the questioner's situation it is because they are soft links, and we use
ls -l
andpip show
to verify the reason.and of course, this answer is to answer his question. -
Torsten Bronger over 5 yearsI don’t think there were symlinks on the questioner’s computer. I don’t find any reference that pip ever worked/works this way.
-
CSJ over 5 yearsas I mentioned, it is depends on how you install it. MacOS users mostly use brew and which will create soft links: github.com/Homebrew/homebrew-core/blob/master/Formula/…
-
CSJ over 5 yearsFor more information, Fedora family, Archlinux family have the same way: src.fedoraproject.org/cgit/rpms/python-pip.git/tree/…, git.archlinux.org/svntogit/packages.git/tree/trunk/…
-
CSJ over 5 yearsFor Debian family is different: salsa.debian.org/python-team/modules/python-pip/blob/master/…
-
apadana over 5 years@TorstenBronger What you mentioned is installing pip, not installing python. The answer talks about installing python.
-
Torsten Bronger over 5 yearsThe respective Python version is installed as a dependency by installing the respective pip version. The naked Ubuntu container has no Python version pre-installed.
-
Torsten Bronger over 5 yearsI just installed pip/pip3 in current ArchLinux and Fedora containers: No symlinking. RHEL doesn't do it either. I cannot test Mac, though, but this Homebrew script even links python3 to python, which is a disastrously bad idea.
-
apadana over 5 years@TorstenBronger Anyway your scenario is different from what the answer is saying. The answer talks about installing python directly. Hope that clears the confusion.
-
apadana over 5 years@TorstenBronger Also the OP asked about Mac, not Ubuntu.
-
Torsten Bronger over 5 yearsYou can also install Python2/3 directly – same result.
-
apadana over 5 years@TorstenBronger How do you install python2/3 so I can try to reproduce?
-
Roland over 3 yearsexpectations: agree. This problem started with having Python 3 not really compatible with Python 2
-
JL Peyret over 3 years@Roland it's got extremely little to do with 2 vs 3 and a lot more with path management and pip's often obscure relationship with python and the python version. just figuring out how to install pip with python at all is a pain in the neck, at least on macOS. And so is pip's insistence to come in as an obsolete version most of the time, which needs immediate updating.
-
Roland over 3 yearsOf course you are correct. But your explanation shows the complexity leading to my misunderstanding. Learning Fortran was easy, same Pascal, Lisp, C, C++, C#, JS, Python. Building linux, setting up X Windows, Apache, that's doable. But setting up python, that really beats me :-(
-
TylerH about 2 yearsThis really should be a comment because it does not provide an answer to the question(s) being posed, just says "it depends" and doesn't even go into detail about what it depends on.