I have both python2 and python3 in my system. But when I try :
python -m pip install sklearn
bash shows :
/usr/bin/python: No module named pip
And
pip --version
Yields :
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Python versions are Python 2.7.18 and Python 3.8.2.
How to correct this error by having two pip versions?
This is a similar question, but did not solve the issue.
OS is Ubuntu.
Thanks to HK boy
The following works, it installs pip explicitly for the python version specified :
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
I already had pip3 before hand, so to install packages for python3, pip3 install <package> is enough.
I'm setting up virtual env. I was getting warnings about an outdated pip (19.2) so I updated pip on my (macos) system globally, sudo -H python3 -m pip install --upgrade pip. It seems to have worked, but when I make a new venv, I'm still getting the old pip version.
% pip --version
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% python3 -m pip --version
pip 20.1 from /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)
% rm -rf .venv # make sure
% python3 -m venv .venv
% . .venv/bin/activate
(.venv) % python3 -m pip --version
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)
(.venv) % pip --version
pip 19.2.3 from /Users/marvin/.venv/lib/python3.8/site-packages/pip (python 3.8)
Where is the older version coming from?
Pip is installed anew in any freshly created venv. The venv's default pip version is associated with the Python version, and is completely independent from whatever pip version you may have installed on the system. The older version comes from a wheel file bundled with the stdlib ensurepip module. This allows users to create a venv even with no internet connection available, as the venv docs mention:
Unless the --without-pip option is given, ensurepip will be invoked to bootstrap pip into the virtual environment
You can check the bundled pip version with ensurepip.version:
>>> import ensurepip
>>> ensurepip.version()
'19.2.3'
Python 3.8.2 is vendoring pip 19.2.3 and setuptools 41.2.0, matching what you've seen.
To create venvs directly with the latest pip version, rather than creating them with an older pip and then upgrading the pip version, refer to this answer:
How to get “python -m venv” to directly install latest pip version
I have python 2.7 & 3.5 on my system. When I use sudo, easy_install, or pip to install a package it installs to 2.7.
How do I tell pip, sudo, easy_install to install the package to 3.5?
Example:
This installs pytest to 2.5
pip install -U pytest
What would be the equivalent to install to 3.5?
The simplest way to install any pip package with specifying version is:
For Python 2.7:
pip install <package_name>
For Python 3.x
pip3 install <package_name>
This works on all the platforms, be it Linux, Windows or Mac if you have pip package manager installed.
It seems you're trying to install packages using pip on mac. Since the default python version is 2.7 for mac therefore the default pip also installs to python 2.7. In order to install to a custom version you can specify it like this:
python3 -m pip install package
#or
python3.5 -m pip install package
#ie
python3.5 -m pip install -U pytest
On Windows, use the py Python launcher in combination with the -m switch:
es:
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4
On Linux, Mac OS X, and other POSIX systems, use:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it doesn't work when I upgrade it.
You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running pip3 install --upgrade pip.
It might be a good idea to take some time and read about virtual environments in Python. It isn't a best practice to install all of your packages to the base python installation. This would be a good start: http://docs.python-guide.org/en/latest/dev/virtualenvs/
To upgrade your pip3, try running:
sudo -H pip3 install --upgrade pip
Your pip may move from /bin to /usr/local/bin
To upgrade pip as well, you can follow it by:
sudo -H pip2 install --upgrade pip
Try this command:
pip3 install --upgrade setuptools pip
First decide which pip you want to upgrade, i.e. just pip or pip3.
Mostly it'll be pip3 because pip is used by the system, so I won't recommend upgrading pip.
The difference between pip and pip3 is that
NOTE: I'm referring to PIP that is at the BEGINNING of the command
line.
pip is used by python version 2, i.e. python2
and
pip3 is used by python version 3, i.e. python3
For upgrading pip3: # This will upgrade python3 pip.
pip3 install --upgrade pip
For upgrading pip: # This will upgrade python2 pip.
pip install --upgrade pip
This will upgrade your existing pip to the latest version.
The Problem
You use pip (the Python 2 one). Now you want to upgrade pip (the Python 3 one). After that, pip is the Python 3 one.
The solution
Use pip2 and pip3. This way it is explicit.
If you want to use pip, just check where it is (which pip) and change the link. For example:
$ which pip
/usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
$ which pip2
/usr/local/bin/pip2
$ sudo rm /usr/local/bin/pip
$ sudo ln -s /usr/local/bin/pip2 /usr/local/bin/pip
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
for Python 3:
python3 -m pip install --upgrade pip
for Python 2:
python2 -m pip install --upgrade pip
What worked for me was the following command:
python -m pip install --upgrade pip
pip3 install --upgrade pip worked for me
In Ubuntu 18.04, below are the steps that I followed.
python3 -m pip install --upgrade pip
For some reason you will be getting an error, and that be fixed by making bash forget the wrongly referenced locations using the following command.
hash -r pip
If you have 2 versions of Python (eg: 2.7.x and 3.6), you need do:
add the path of 2.x to system PATH
add the path of 3.x to system PATH
pip3 install --upgrade pip setuptools wheel
for example, in my .zshrc file:
export PATH=/usr/local/Cellar/python#2/2.7.15/bin:/usr/local/Cellar/python/3.6.5/bin:$PATH
You can exec command pip --version and pip3 --version check the pip from the special version. Because if don't add Python path to $PATH, and exec pip3 install --upgrade pip setuptools wheel, your pip will be changed to pip from python3, but the pip should from python2.x
This worked for me (mac)
sudo curl https://bootstrap.pypa.io/get-pip.py | python
If you try to run
sudo -H pip3 install --upgrade pip3
you will get the following error:
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
but if you upgrade using the suggested command:
pip install --upgrade pip
then, the legacy pip will be upgraded, so what I did is the following:
which pip3
and I located my pip3 installation (just in case the following command wouldn't upgrade the legacy pip. Then i changed to that directory and upgraded pip3 using the following commands: (your directory could be different)
cd /Library/Frameworks/Python.framework/Versions/3.8/bin
sudo -H pip3 install --upgrade pip
after this:
pip --version
will still show the legacy version, while
pip3 --version
will show pip 21.0.1
My installation of pip seems to be convinced it is out of date:
$ sudo pip install editable .
<my stuff gets installed>
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip --version
pip 8.1.2 from /home/wash/.local/lib/python2.7/site-packages (python 2.7)
$ python --version
Python 2.7.11+
I am running Debian 8.0. I've tried running pip install --upgrade pip as it has requested.