Verified guide
This guide was verified by creating a cloud server and running every command in it, from start to finish, exactly as written.
- OS
- Ubuntu 26.04.1 LTS · x86_64
- Installed version
- Python 3.15.0, Python 3.13.16, uv 0.13.1
- Test server
- DigitalOcean · 2 vCPU / 2 GB RAM / 60 GB SSD (s-2vcpu-2gb, sgp1)
- Last checked
- 2026-10-16
This guide contains affiliate links. If you sign up through them, Codesand may earn a commission. This doesn't affect the content or our assessments.
This guide installs the latest Python on an Ubuntu 26.04 server with uv, then covers installing several versions, setting the Python version per project, virtual environments and package installation, fixing the uv command-not-found error and ModuleNotFoundError, and removing everything cleanly.
1. Requirements
- One Ubuntu 26.04 LTS server or PC
- A regular user account with
sudoprivileges - An internet connection (files are downloaded from GitHub and PyPI)
If you don't have a server, try creating a DigitalOcean Droplet. Every step in this guide was verified on a Droplet (2 vCPU, 2 GB memory, 60 GB SSD, Ubuntu 26.04, Singapore) using a regular user account with sudo privileges.
2. Check the state before installing
Ubuntu 26.04 comes with Python 3.14. System programs use this Python, so do not remove it or replace it with another version.
python3 --versionPython 3.14.4There is no python command. Ubuntu provides Python only under the name python3.
python --versionCommand 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3pip3, which installs packages, is not available either, and venv, which creates virtual environments, cannot be used right away.
pip3 --versionCommand 'pip3' not found, but can be installed with:
sudo apt install python3-pippython3 -m venv myenvThe virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.14-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: /home/devuser/myenv/bin/python3The failed command leaves a half-created myenv folder behind, so delete it. There is no output.
rm -rf myenvPython 3.14 is supported until October 2030, and the latest Python on the day this guide was verified was 3.15. This guide leaves the system Python as it is and installs the latest Python separately in your user folder with uv. uv is a single tool that handles Python installation, version changes, virtual environments, and package installation. Because it downloads prebuilt Python, installation finishes within a minute and does not need sudo.
3. Install uv
Download and run the uv install script. curl -LsSf downloads without a progress display and shows an error if the download fails. The downloaded script is passed to | sh and runs right away. This guide installed uv 0.13.1, the latest version on the day it was verified.
curl -LsSf https://astral.sh/uv/install.sh | shdownloading uv 0.13.1 x86_64-unknown-linux-gnu
installing to /home/devuser/.local/bin
uv
uvx
everything's installed!
To add $HOME/.local/bin to your PATH, either restart your shell or run:
source $HOME/.local/bin/env (sh, bash, zsh)
source $HOME/.local/bin/env.fish (fish)uv is installed in the ~/.local/bin folder, and a line that adds this folder to the command path (PATH) is appended to the end of ~/.bashrc and ~/.profile.
4. Verify the uv installation
If you run uv right away in the terminal where you installed it, you get a message that the command cannot be found. This is because the terminal was opened before the PATH line was added.
uv --versionuv: command not foundRun the command below as the install message suggests, or close the terminal and open a new one (for SSH, disconnect and reconnect). There is no output.
source $HOME/.local/bin/envuv --versionuv 0.13.1 (x86_64-unknown-linux-gnu)5. Install the latest Python
If you do not specify a version, uv installs the latest Python.
uv python installInstalled Python 3.15.0 in 2.79s
+ cpython-3.15.0-linux-x86_64-gnu (python3.15)Check the list of installed Python versions. The Python installed by uv and the system Python (/usr/bin) are shown together.
uv python list --only-installedcpython-3.15.0-linux-x86_64-gnu .local/bin/python3.15 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.14.4-linux-x86_64-gnu /usr/bin/python3.14
cpython-3.14.4-linux-x86_64-gnu /usr/bin/python3 -> python3.14uv registers the installed Python only under a versioned name such as python3.15. So python3.15 runs, but python still cannot be found.
python3.15 --versionPython 3.15.0python --versionCommand 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3To run Python 3.15 as python and python3 as well, install it again with --default. Python is already downloaded, so only the names are added. This option is still experimental, so a warning is shown, but the installation works.
uv python install 3.15 --defaultwarning: The `--default` option is experimental and may change without warning. Pass `--preview-features python-install-default` to disable this warning
Installed Python 3.15.0 in 86ms
+ cpython-3.15.0-linux-x86_64-gnu (python, python3)python --versionPython 3.15.0python3 --versionPython 3.15.0which python/home/devuser/.local/bin/python6. Install another version
If you need another version, specify the version number. Writing 3.13 installs the latest release in the 3.13 series.
uv python install 3.13Installed Python 3.13.16 in 2.25s
+ cpython-3.13.16-linux-x86_64-gnu (python3.13)uv python list --only-installedcpython-3.15.0-linux-x86_64-gnu .local/bin/python3.15 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu .local/bin/python3 -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu .local/bin/python -> .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.15.0-linux-x86_64-gnu .local/share/uv/python/cpython-3.15-linux-x86_64-gnu/bin/python3.15
cpython-3.14.4-linux-x86_64-gnu /usr/bin/python3.14
cpython-3.14.4-linux-x86_64-gnu /usr/bin/python3 -> python3.14
cpython-3.13.16-linux-x86_64-gnu .local/bin/python3.13 -> .local/share/uv/python/cpython-3.13-linux-x86_64-gnu/bin/python3.13
cpython-3.13.16-linux-x86_64-gnu .local/share/uv/python/cpython-3.13-linux-x86_64-gnu/bin/python3.13Python 3.13 can be run as python3.13, and python stays at 3.15. Step 8 explains how to use a different version per project.
7. Create your first project and install a package
uv creates a virtual environment (.venv) in each project folder and manages packages separately for each project. Open a new terminal and create the hello-python project. --no-package means the project starts with a single main.py instead of a distributable package layout.
uv init --no-package hello-pythonInitialized project `hello-python` at `/home/devuser/hello-python`cd hello-pythonls -a. .. .git .gitignore .python-version README.md main.py pyproject.toml.python-version is a file that records the Python version this project uses. It contains 3.15, the newest of the installed Python versions. main.py contains an example that prints a greeting.
cat .python-version3.15cat main.pydef main():
print("Hello from hello-python!")
if __name__ == "__main__":
main()Run project files with uv run. On the first run, it creates the virtual environment (.venv) and then runs the file.
uv run main.pyUsing CPython 3.15.0
Creating virtual environment at: .venv
Hello from hello-python!Install packages with uv add. Let's install the requests package, which sends HTTP requests. The package goes only into the project's virtual environment and is recorded in pyproject.toml.
uv add requestsResolved 6 packages in 189ms
Prepared 5 packages in 35ms
Installed 5 packages in 9ms
+ certifi==2026.7.22
+ charset-normalizer==3.5.2
+ idna==3.20
+ requests==2.34.2
+ urllib3==2.8.0Replace main.py with code that uses requests and run it. The first line writes the quoted text to the file, so it has no output.
echo "import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)" > main.py
uv run main.pyHello Python 3.15.0 requests 2.34.2If you run the same file directly with python, you get an error that requests cannot be found. This is because requests is installed only in the project's virtual environment.
python main.pyTraceback (most recent call last):
File "/home/devuser/hello-python/main.py", line 1, in <module>
import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)
^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'requests'If you want to run it with python without uv run, activate the virtual environment. The activate command has no output. When you are done, turn it off with deactivate.
source .venv/bin/activatepython --versionPython 3.15.0python main.pyHello Python 3.15.0 requests 2.34.2deactivate8. Set the Python version per project
You can set the version with --python when you create a project. Go back to your home folder and create old-project, which uses Python 3.13.
cd ~uv init --no-package --python 3.13 old-projectInitialized project `old-project` at `/home/devuser/old-project`cd old-projectcat .python-version3.13Check which Python runs in this project with uv run python --version.
uv run python --versionUsing CPython 3.13.16
Creating virtual environment at: .venv
Python 3.13.16To upgrade the version later, use uv python pin. The .python-version file changes, and the virtual environment is recreated with the new version on the next run.
uv python pin 3.15Updated `.python-version` from `3.13` -> `3.15`uv run python --versionUsing CPython 3.15.0
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Python 3.15.0You cannot go down to a lower version directly. See the requires-python item in step 9.
9. Troubleshooting
uv: command not found
This means you ran the command in a terminal that was opened before uv was installed. That terminal was opened before ~/.local/bin was added to PATH. Close the terminal and open a new one, or run source $HOME/.local/bin/env. If a new terminal shows the same message, check that the PATH line exists with grep -n 'local/bin/env' ~/.bashrc.
ModuleNotFoundError: No module named 'requests'
Packages installed with uv add exist only in the project's virtual environment (.venv). If you run python main.py directly, a Python outside the virtual environment runs and cannot find the package. Run it with uv run main.py, or activate the virtual environment with source .venv/bin/activate first.
python main.pyTraceback (most recent call last):
File "/home/devuser/hello-python/main.py", line 1, in <module>
import sys, requests; print('Hello Python', sys.version.split()[0], 'requests', requests.__version__)
^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'requests'error: The requested Python version `3.13` is incompatible with the project `requires-python` value of `>=3.15`.
The Python version used when the project was created is recorded as the minimum version in requires-python in pyproject.toml, so you cannot uv python pin a lower version. If you really need a lower version, first lower the requires-python value in pyproject.toml, or create the project with --python from the start as in step 8.
uv python pin 3.13error: The requested Python version `3.13` is incompatible with the project `requires-python` value of `>=3.15`.The virtual environment was not created successfully because ensurepip is not available.
This message appears when you run python3 -m venv with the system Python (3.14). Ubuntu's system Python lacks the package needed to create virtual environments. Projects created with uv do not need this package because uv creates the virtual environment itself. If you need to create a virtual environment with the system Python, install the package with sudo apt install python3.14-venv as the message suggests.
error: externally-managed-environment
This error appears on Ubuntu 26.04 when you install pip with sudo apt install python3-pip and run pip3 install. Installing packages directly into the system Python can conflict with system packages installed by apt, so Ubuntu blocks it. Do not install into the system Python; install with uv add in a uv project as in step 7.
pip3 install requestserror: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
…10. Uninstall
Go back to your home folder and remove all Python versions installed by uv. The names registered in ~/.local/bin, such as python and python3, are removed as well. The system Python is not removed.
cd ~uv python uninstall --allSearching for Python installations
Uninstalled 2 versions in 118ms
- cpython-3.13.16-linux-x86_64-gnu (python3.13)
- cpython-3.15.0-linux-x86_64-gnu (python, python3, python3.15)Clear the cache where uv keeps downloaded files.
uv cache cleanClearing cache at: .cache/uv
Removed 156 files (1.0MiB)Delete the uv tool folder and the practice project folders, then delete the uv programs and the PATH setup files (env, env.fish). Neither command has output.
rm -rf "$(uv tool dir)" ~/hello-python ~/old-project
rm ~/.local/bin/uv ~/.local/bin/uvx ~/.local/bin/env ~/.local/bin/env.fishCheck and delete the lines added to ~/.bashrc and ~/.profile in step 3. sed -i edits the file in place, and /local\/bin\/env/d deletes lines that contain local/bin/env.
grep -n 'local/bin/env' ~/.bashrc ~/.profile/home/devuser/.bashrc:119:. "$HOME/.local/bin/env"
/home/devuser/.profile:29:. "$HOME/.local/bin/env"sed -i '/local\/bin\/env/d' ~/.bashrc ~/.profilels -a ~/.local/bin. ..Close the terminal, open a new one, and check. If uv cannot be found and python3 is back to the system Python, everything has been removed.
uv --versionuv: command not foundpython3 --versionPython 3.14.4Try it yourself
No server yet? You can spin up an Ubuntu server in a few minutes with one of these providers. We verified this guide on DigitalOcean.
Was this guide helpful? Let us know if anything is wrong or out of date.
Request a correction