How to install Python 3.12 on Ubuntu 23.10?

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 mantic InRelease
Hit:2 mantic-updates InRelease
Hit:3 mantic-backports InRelease
Hit:4 mantic-security InRelease
Hit:5 stable InRelease                  
Hit:6 stable InRelease               
Hit:7 mantic InRelease                        
Hit:8 mantic-updates InRelease                
Hit:9 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

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.

Asked By: user16280919


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.

Answered By: sleepyhead
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.