5

Today I faced a problem regarding pip3 in Ubuntu. Ubuntu comes with python 3.8 but I wanted to use latest versions of python, like 3.9 or maybe 3.10. So I installed it using 'ppa:deadsnakes' repository and also installed pip. But the problem is I want to use pip in python 3.9 instead of version 3.8. So I changed the default python version to 3.9 and everything crashed. So reverted to python 3.8. Whenever I install some package it gets installed using python 3.8. Help me, how can I use python 3.9 pip and install packages in python 3.9 without changing the default version. Any help is appreciated.

--> Thing I want is that when I want to install python package using pip3 install <package_name> it must install in python3.9 and not in python3.8

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Satvir Singh
  • 111
  • 1
  • 1
  • 6

4 Answers4

10

You don't need to install pip separately

You should be able to refer to it as such

python3.9 -m pip install

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Yes there is pip shipped with python but in Ubuntu we have to explicitly install pip using ```sudo apt install python3-pip```. – Satvir Singh Apr 12 '21 at 14:42
  • 1
    I only ever use pip through this method. I never run bare pip. – JonSG Apr 12 '21 at 15:16
  • @Satvir All Python3 distributions since 3.4 come with their own Python. That's not unique to Ubuntu. Does this answer solve your problem? – OneCricketeer Apr 13 '21 at 12:46
  • @OneCricketeer I cannot use pip using the command mentioned without installing the pip explicitly in Ubuntu. If I install explicitly than it is working. – Satvir Singh Apr 13 '21 at 16:15
  • why is this the case for Ubutu? This solution worked, but I typically am used to using pip3, or finding where python3 is installed and specifying the full path to pip at worst case scenario – dataviews Dec 07 '21 at 04:55
  • 1
    @dataviews pip comes installed with Python3.4+, however its binary / symlink can get overridden due to poor management of Python environments or PATH changes. Therefore it's suggested to always use `python -m pip` to verify that you're actually installing packages into the correct python environment (on any OS) – OneCricketeer Dec 07 '21 at 14:02
4

Hello everyone I fixed my issue. The problem is we cannot override default python version in Ubuntu as so many things depend on it. So I just made an alias as : alias pip3='python3.9 -m pip' and alias for python : alias python3='/usr/bin/python3.9'

If anyone face this issue please do what I specify and you will be good to go. Now all my packages are being installed in python3.9.

Satvir Singh
  • 111
  • 1
  • 1
  • 6
2

Currently all python3 versions are using the same pip version which can be installed by:

sudo apt-get install python3-pip

The easiest way to work with a specific python version is creating a virtualenv and working under it. When working with a virtualenv you can use pip freely without worrying about which python version it belongs.

NirO
  • 216
  • 2
  • 12
-1

you can use pip for python3.9 by pip3.9 install <package-name>

Sarthak Kumar
  • 304
  • 5
  • 16
  • 1
    There is no such thing like you have mentioned above. Only ```pip3 install ``` works in Ubuntu. – Satvir Singh Apr 12 '21 at 14:44
  • That would depend on how/where Python gets installed from. Some packages do include `pipX.Y` binaries. Otherwise, add to your bashrc `alias pip3.9='python3.9 -m pip'` @SatvirSingh – OneCricketeer Aug 06 '21 at 08:17