2

I did several wrong things for my first day on Ubuntu when trying to code with Python, so I just reinstalled it. Can anyone tell me the best way to install Python here? I am using Ubuntu 20.04, and I am updating to Ubuntu 23.10 right now.

I see sudo apt install python3? OK, but it was why my Ubuntu was corrupted. Can anyone tell me how to get complete python installed without breaking any programs - with python pip, venv, and whatever else is needed.

Someone asked why do I need latest the python version. I just prefer it, but I want any Python 3 (I prefer to use 3.9 and new always).

I did not install any Python. The only thing I did was sudo apt install python3-pip and also python3-venv (and python3.11-venv), venvs failed to install but why does VSCode show 4 different Python interpreters now? I didn't install any python version. I installed Ubuntu 20.04 from an ISO file, and upgraded to 23.10. The default Python package on Ubuntu 23.10 is python3.12.

Image of VSCode showing Python interpreters:

Image of VSCode showing interpreters

ashish@ashish-pc:~$ pip3 --version
pip 23.1.2 from /usr/lib/python3/dist-packages/pip (python 3.11)
ashish@ashish-pc:~$ pip3 --version
pip 23.1.2 from /usr/lib/python3/dist-packages/pip (python 3.11)
ashish@ashish-pc:~$ sudo apt-get update && sudo apt-get install python3-venv
Hit:1 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic InRelease
Hit:2 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-updates InRelease
Hit:3 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-backports InRelease
Hit:4 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-security InRelease
Hit:5 https://dl.google.com/linux/chrome/deb stable InRelease                  
Hit:6 https://packages.microsoft.com/repos/code stable InRelease               
Hit:7 http://archive.ubuntu.com/ubuntu mantic InRelease                        
Hit:8 http://archive.ubuntu.com/ubuntu mantic-updates InRelease                
Hit:9 http://security.ubuntu.com/ubuntu mantic-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: python3-venv : Depends: python3.11-venv (>= 3.11.2-1~) but it is not going to be installed Depends: python3 (= 3.11.2-1) but 3.11.4-5 is to be installed E: Unable to correct problems, you have held broken packages. ashish@ashish-pc:~$ ^C ashish@ashish-pc:~$

I used sudo apt install python3-pip it worked and I got pip. Now when I tried sudo apt install python3-venv it generated an error message. I just noticed that the python -m venv command exists.

karel
  • 114,770
  • Please specify why you need to have the latest Python, exactly what is it in there that you "must have". Edit your question and add text there. -> https://docs.python.org/3/whatsnew/3.12.html – Hannu Mar 16 '24 at 06:15
  • I'm sorry, I did it. I am new to stack overflow. – user16280919 Mar 16 '24 at 06:37
  • Ubuntu relies on the Python version coming from the official sources, as parts of the system need it. This is the Python version which is installed with sudo apt install python3. This system should NEVER be replaced with another Python release, as this may break your system up to being not usable anymore. However, multiple Python version can be installed in parallel without conflicting by compiling other version yourself and making sure to not replace the system's version while installing. – noisefloor Mar 16 '24 at 08:00
  • Ok, but can you tell me if I did it wrong: sudo apt install python3-pip. Do I uninstall it now before executing next command because I do not want to corrupt it again.

    Also, you meant to do that command? (3.11 is installed by default on my Ubuntu 23.10) To install python? Ok, but it would install pip+venv or no? I need those with my Python

    – user16280919 Mar 16 '24 at 08:41
  • I tried installing pip, it worked, but venv failed. Read the edited msg for more! – user16280919 Mar 16 '24 at 08:43
  • Ubuntu packages these separately. If you want venv you also have to install it with ... sudo apt install python3-virtualenv – sleepyhead Mar 16 '24 at 10:31
  • Thank you. Do I delete the post or do what to say its answered? For others, you could post a answer and I mark it as answer so we can close it? – user16280919 Mar 16 '24 at 13:12
  • 1
    I rewrote the comment as an answer, you can accept it, but in general it doesnt close a question, others can write their own answers and update those. Only bad questions that attract bad answers get closed, otherwise you can leave questions open for others to find and solve their own problems. – sleepyhead Mar 16 '24 at 13:50

1 Answers1

2

Ubuntu packages all python3 packages separately. By installing python3-pip it also installed the base python3. If you want venv you also have to install it with

sudo apt install python3-virtualenv

Python2 and Python3 have major incompatible differences, but the python3 that ships with Ubuntu will be maintained and you'll get the latest patches with an apt upgrade Ubuntu is stable and updates are generally safe.

sleepyhead
  • 578
  • 2
  • 6