Programming Language
2025-01-08
Add Python PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
This also outputs a list of the latest Python versions for each distro.
Update local PPA cache:
sudo apt update
Install selected version:
sudo apt-get install python3.12 python3-pip
Some Python-based projects require a virtual env.
When a venv is activated for a proj, pip
will install all pkgs in [project_dir]/.venv
. This isolates the proj with its own specific Python interpreter, and software libs and binaries.
Create .venv
under proj dir:
cd [proj-dir]
python3 -m venv .venv
Activate Python virtual env:
source .venv/bin/activate
pip
will now install every Python pkg into ./.venv
until venv is deactivated (exit
or Ctrl-C or close terminal).
A project's venv must be re-activated (source .venv/bin/activate
) to install more pkgs or run services.
.bash_aliases
alias activate-venv="source ./.venv/bin/activate"
To list installed pkgs while venv is activated:
pip list