Whether the correct command for Python 3 is pip
or pip3
or (say) gaschplutzga
depends on a number of factors.
If you only have Python 3, and you have a command named pip
, that's probably safe to use. Going forward, this will be the simple, obvious, safe answer in more and more places.
If you have both Python 2 and Python 3, and there is a command called pip3
installed on your system, probably that's the correct one to use.
More generally, you can go through your PATH
and look for commands with suitable names. On Unix-like systems with a POSIX-compatible shell, try the commands command -V pip3
and command -V pip
. (On Windows systems, maybe try where pip3
and where pip
, or pray to whatever dark deity informed your choice of operating system.)
If you receive output like
/opt/random/nonstandard/whoa/pip
/usr/local/bin/pip
/usr/bin/pip
you can try each of these in turn with the full path and adding the --version
option to have them identify themselves. When you specify the full path, you are bypassing the system's PATH
mechanism entirely. For example,
/opt/random/nonstandard/whoa/pip --version
might identify itself as belonging to Python version 3.2.1. If that's the one you want, and it's at the top of your PATH
, you can simply rely on the PATH
to give you this version when you type just pip
. If not, perhaps you can shuffle your PATH
(but understand that this changes the resolution order for all commands in the directory whose position you change) or create a simple alias or wrapper which bypasses the PATH
for this particular command in your personal account. On Unix-like systems with a POSIX-compatible shell, this might look like
alias pip=/opt/random/nonstandard/whoa/pip
(to persist this across sessions, you'd add this to your .profile
or similar - for Bash, try .bash_profile
if it exists; for Zsh, try .zshrc
. The full scoop for each shell is more complicated than I can squeeze into these narrow parentheses); on Windows, you might be able to control this by setting the environment variable PY_PYTHON
, but there's a huge can of worms behind that "might".
Some sites and OSes / distros have additional wrappers or conventions which introduce additional options; if you use a specific package manager, perhaps also study its documentation. (One common example is Anaconda, though I don't believe it affects the naming or location of pip
specifically.)
One common arrangement is to use python -m pip
instead of the bare pip
command; this reasonably expects that whichever python
version you run will be able to figure out how to find its specific version of pip
from its module library. Everything about how to select a specific pip
binary above also applies to the logic for finding a specific python
binary; so (as long as it isn't pathologically misconfigured) /opt/random/nonstandard/whoa/python -m pip
will run the correct pip
version for that Python version. You could argue that this only pushes the problem to a different corner, but it's convenient if you have multiple Python versions to have a simple way to select the correct pip
for each with a simple, unified mechanism.
On Windows, probably use py -m pip
and expect the py
wrapper to select the correct Python binary. The py
command offers convenience functionality to select either Python 2 or Python 3 if both are installed. Going forward, there are plans to make this wrapper available on other platforms, too.