User local install as much as possible, leaving system-wide kit (e.g. python & python-pip .debs) alone. Tested on Debian, Ubuntu, Mint & ChromeOS/Crostini.
Set up the dev environment (this is the only system-wide part):
sudo apt install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev
#Optionally:
sudo apt install libxml2-dev libxslt1-dev git mercurial
mkdir -p $HOME/.local/venv
mkdir -p ~/src
# mkdir -p ~/Downloads # If needed
cd ~/Downloads
wget https://www.python.org/ftp/python/3.10.4/Python-3.10.4.tar.xz
cd ~/src
tar xvf ~/Downloads/Python-3.10*
cd Python-3.10.4
./configure --enable-optimizations --prefix=$HOME/.local
make; make install
Create:
export DEVENVTAG=main
$HOME/.local/bin/python3 -m venv $HOME/.local/venv/$DEVENVTAG
You only need to specify the full path to Python when creating the venv, as above.
Activate:
source $HOME/.local/venv/$DEVENVTAG/bin/activate
pip install wheel #Recommended; One time per venv
pip install --upgrade pip #Needed from time to time, to make sure pip itself is up to date
In future you only need the first line above to activate the venv.
First of all you can check whether the Debian version you want has the Python version you want. In April 2022 a query:
https://packages.debian.org/search?keywords=python+3.10
Indicated that the 3.10 version was only in testing and unstable, not in stable (when installed you got 3.10.4).
Stable had Python 3.9 (3.9.2)
https://packages.debian.org/search?keywords=python+3.9
You can install Python 3 and other dev environment bits system-wide
sudo apt install python3 python3-dev python3-venv
Though I still recommend sticking to .local
and not mucking with system-level Python versions at all.