I am using OSX and I have pip installed for both Python3.5 and Python2.7. I know I can run the command pip2
to use Python2 and when I use the command pip3
It works for me:
As super-user
Uninstall pip
sudo pip uninstall pip
Install pip
sudo python3 -m pip install --upgrade --force pip
Check install path
sudo pip -V
As local-user
Uninstall pip
pip uninstall pip
Install pip
python3 -m pip install --upgrade --force pip
Check install path
pip -V
Since you have specified in the comments you want syntax like pip install [package]
to work, here is a solution:
Install setuptools
for Python3
: apt-get install python3-setuptools
Now pip
for Python3
could be installed by: python3 -m easy_install pip
Now you can use pip
with the specific version of Python to
install package for Python 3 by: pip-3.2 install [package]
Can't you alias pip='pip3'
in your ~/.bash_profile
?
In Terminal, run nano ~/.bash_profile
, then add a line to the end that reads alias pip='pip3'
. This is safe; it won't affect system processes, only your terminal.
For your projects, you should be using a virtualenv.
You can choose which python will be that of the virtualenv at creation time, by specifying it on the command line:
virtualenv -p python3 env
# then
. env/bin/activate
python # ← will run python3
That python interpreter will be the one used when you run python
or pip
while the virtualenv is active.
Under the hood, activating the virtualenv will:
PATH
environment setting so binaries in env/bin
override those from your system.PYTHONHOME
environment setting so python modules are loaded from env/lib
.So python
, pip
and any other package you install with pip
will be run from the virtualenv, with the python version you chose and the package versions you installed in the virtualenv.
Other than this, running python
without using virtualenv will just run the default python of the system, which you cannot usually change as it would break a lot of system scripts.
I always just run it via Python itself, this way:
python3 -m pip install some_module
or
python2 -m pip install some_module
The -m
calls the __main__.py
module of a specified package. Pip supports this.
Run this:
pip3 install --upgrade --force pip
or even more explicit:
python3 -m pip install --upgrade --force pip
This will install pip for Python 3 and make Python 3 version of pip default.
Validate with:
pip -V