How do I install pip for python 3.8 on Ubuntu without changing any defaults?
While we can use pip
directly as a Python module
(the recommended way):
python -m pip --version
This is how I installed it (so it can be called directly):
Firstly, make sure that command pip
is available and it isn't being used by pip
for Python 2.7
sudo apt remove python-pip
Now if you write pip
in the Terminal, you'll get that nothing is installed there:
pip --version
Output:
Command 'pip' not found, but can be installed with:
sudo apt install python-pip
Install python3.8
and setup up correct version on python
command using update-alternatives
(as done in the question).
Make sure, you have python3-pip
installed:
(This won't work without python3-pip
. Although this will install pip 9.0.1 from python 3.6
, we'll need it.)
sudo apt install python3-pip
This will install pip 9.0.1
as pip3
:
pip3 --version
Output:
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
Now, to install pip
for Python 3.8
, I used pip
by calling it as a python module
(ironic!):
python -m pip install pip
Output:
Collecting pip
Downloading https://files.pythonhosted.org/packages/36/74/38c2410d688ac7b48afa07d413674afc1f903c1c1f854de51dc8eb2367a5/pip-20.2-py2.py3-none-any.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 288kB/s
Installing collected packages: pip
Successfully installed pip-20.2
It looks like, when I called pip
(which was installed for Python 3.6, BTW) as a module of Python 3.8, and installed pip
, it actually worked.
Now, make sure your ~/.local/bin
directory is set in PATH
environment variable:
Open ~/.bashrc
using your favourite editor (if you're using zsh
, replace .bashrc
with .zshrc
)
nano ~/.bashrc
And paste the following at the end of the file
# set PATH so it includes user's private bin if it existsif [ -d "$HOME/.local/bin" ] ; then PATH="$HOME/.local/bin:$PATH"fi
Finally, source your .bashrc
(or restart the Terminal window):
source ~/.bashrc
Now if you try running pip
directly it'll give you the correct version:
pip --version
Output:
pip 20.2 from /home/qumber/.local/lib/python3.8/site-packages/pip (python 3.8)
Sweet!
As suggested in official documentation you can try with get-pip.py.
wget https://bootstrap.pypa.io/get-pip.pypython3.8 get-pip.py
This will install pip as pip3.8
Another solution would be to install the pip that is in apt. sudo apt install python3-pip
. The version of the pip that it installs is for all versions of Python not only for version 3.6 once installed you just need to update the pip with the command python3. 8 -m pip install pip
and he will be install the latest version of pip for Python.
I would not advise you to remove Python2 because it is an important module for the system you should just create a permanent "alias" in .bashrc
for Python3 I did like this alias python="python3.8
.