This guide walks you through installing Python 3 on Ubuntu, covering both the default repository method and the more up-to-date deadsnakes PPA. You’ll end up with a working Python 3 interpreter, pip, and venv, ready for scripting or development.
What You’ll Need
- An Ubuntu system (desktop or server) with sudo access
- An internet connection
- Basic comfort with the terminal (Ctrl+Alt+T on desktop)
Step-by-Step
- Check if Python 3 is already installed. Ubuntu often includes Python 3 by default. Open a terminal and run:
python3 --version. If it shows something likePython 3.12.3, you’re already set. If not, continue. - Update your package lists. Run
sudo apt updateto refresh the repository index. This ensures you get the latest available versions. - Install Python 3 from the official Ubuntu repository. Run
sudo apt install python3. This installs the default Python 3 version for your Ubuntu release. It’s the safest option for system compatibility. - Verify the installation. Run
python3 --versionagain. You should see the version number you just installed. Also check pip withpython3 -m pip --version(if pip isn’t installed, see the common mistakes section). - Install pip and venv (recommended). For managing packages and creating isolated environments, run:
sudo apt install python3-pip python3-venv. This gives you the tools to install libraries and manage project dependencies. - Test a simple script. Create a file named
test.pywithprint("Hello, Python!")and run it withpython3 test.py. You should see the output. - Optional: Install a newer Python version via deadsnakes PPA. If you need a version newer than what your Ubuntu release provides (e.g., Python 3.13 on Ubuntu 22.04), add the deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa, thensudo apt update, then install withsudo apt install python3.13. Note: this installs alongside the system Python, so you’ll call itpython3.13specifically. - Set up the
python3command (if you installed from PPA). The PPA version won’t replace your system’spython3command. To use the new version as your default, you’d need to update your shell’s PATH or create an alias, but be cautious—many system tools depend on the system Python.
Common Mistakes
- Using
pythoninstead ofpython3. On most Ubuntu systems,pythonpoints to Python 2 (or doesn’t exist). Always usepython3. - Forgetting to install pip separately. On some Ubuntu versions, pip isn’t included with the base
python3package. You needsudo apt install python3-pip. - Running
sudo pip install. This can interfere with system packages. Usepython3 -m pip install --useror, better, create a virtual environment. - Mixing up PPA versions. If you install from deadsnakes, you must use the specific command like
python3.13, notpython3.
Tips
- Always use virtual environments for projects:
python3 -m venv myenv, thensource myenv/bin/activate. This keeps dependencies isolated. - To upgrade pip, use
python3 -m pip install --upgrade pip. - If you need multiple Python versions, consider using
pyenvfor more control, but the deadsnakes PPA is simpler for most users. - Check what version your Ubuntu release officially supports at
https://packages.ubuntu.comto avoid compatibility issues.
Troubleshooting
- “Command ‘python3’ not found” after installation. This is rare, but if it happens, try
sudo apt install --reinstall python3. Also check that/usr/bin/python3exists. - pip not found. Run
sudo apt install python3-pip. If it’s still not found, trypython3 -m ensurepip. - Permission errors when installing packages. Don’t use sudo. Use
python3 -m pip install --user package-nameor activate a virtual environment first. - Python 3.13 installed but
python3still shows old version. This is expected. Usepython3.13explicitly. To make it the default, you’d need to modify your PATH, but be careful—system scripts may break. - “add-apt-repository: command not found”. Install it with
sudo apt install software-properties-common. - Errors about missing dependencies when installing from PPA. Run
sudo apt --fix-broken installto resolve dependency issues.
Frequently Asked Questions
Is Python 3 preinstalled on Ubuntu?
Yes, most modern Ubuntu releases (20.04 and later) include Python 3 by default. You can check with python3 --version.
What’s the difference between python3 and python?
python3 explicitly points to Python 3.x. On Ubuntu, python may point to Python 2 (deprecated) or not exist at all. Always use python3.
How do I install a specific Python version like 3.10?
Use the deadsnakes PPA: sudo add-apt-repository ppa:deadsnakes/ppa, then sudo apt update, then sudo apt install python3.10.
Do I need to install pip separately?
On some Ubuntu versions, pip is not included with the base Python 3 package. Install it with sudo apt install python3-pip.
Can I uninstall the system Python?
No. Ubuntu’s system tools and GUI depend on it. Removing it can break your system. If you need a different version, install it alongside.
How do I run a Python script?
Save your code in a file (e.g., script.py), then run python3 script.py in the terminal from the same directory.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Google Chrome Helper: What It Is & How to Disable
- Fix 0x80070422 on Windows Server (Step-by-Step)
- How to Troubleshoot a Malfunctioning Driver on Windows
- How to Create Folders in Microsoft Outlook
- Fix Status Range List Conflict 0xc0000282 in Windows
- Fix Software Not Uninstalling on Windows 10