Goals of this page #
- Install Python 3.13 and
uvon Ubuntu 22.04 / 24.04 LTS - Create, activate, and manage a virtual environment for your study projects
- Spot common pitfalls and know the checks to run when something fails
Prerequisites #
| Item | Details |
|---|---|
| Privileges | Ability to run sudo for package management |
| Terminal | Open with Ctrl + Alt + T or from the application menu |
| Working folder | Example: ~/projects/my-app (adjust if desired) |
1. Install Python 3.13 #
Ubuntu窶冱 default repositories don窶冲 ship Python 3.13 yet, so add the deadsnakes PPA.
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install -y python3.13 python3.13-venv python3.13-dev python3.13-distutils
python3.13 --version
Seeing Python 3.13.x confirms success.
2. Install uv #
curl -LsSf https://astral.sh/uv/install.sh | sh
~/.local/bin/uv --version
If the command is not found, add ~/.local/bin to your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
3. Create the project folder and virtual environment #
mkdir -p ~/projects/my-app
cd ~/projects/my-app
uv venv --python 3.13 .venv
source .venv/bin/activate
When you see (.venv) in the prompt, the environment is active. Use deactivate to exit.
庁 You can also skip activation and run
uv run python script.py;uvwill reuse the environment automatically.
4. Add and sync libraries #
uv pip install numpy pandas
uv pip list
uv pip sync requirements.txt
uv pip install: add packagesuv pip list: inspect what窶冱 installeduv pip sync: rebuild the environment fromrequirements.txt
5. Connect with editors (VS Code, etc.) #
- In VS Code install the 窶弃ython窶・extension, press
Ctrl+Shift+P, choosePython: Select Interpreter, and pick.venv/bin/python. - For CLI editors such as
vim/neovim, simply start them from the shell where the environment is activated.
6. Common issues #
| Issue | Fix |
|---|---|
add-apt-repository missing | Run sudo apt install software-properties-common |
uv still not in PATH | Append ~/.local/bin to PATH and reload the shell |
Permission denied when creating .venv | Check directory ownership (ls -ld .) and adjust with chown if necessary |
7. Clean-up #
- Leave the environment:
deactivate - Remove the environment:
rm -rf .venv - Record dependencies:
uv pip freeze > requirements.txt
Your Ubuntu environment now runs Python 3.13 with uv. For comparison, review the guides for Windows and macOS, then continue to the syntax chapter and start coding.
When you’re ready, move on to the next lesson to start learning Python.