Python 3 is
pre-installed on all modern Ubuntu versions. You should not remove or change the system's default Python version as it can break core system tools. For most use cases, you just need to install additional modules like pip and venv or a specific Python version alongside the system's default.Using the Pre-installed Python 3
Open your terminal (Ctrl + Alt + T) and follow these steps:
- Update package lists:bash
sudo apt update - Verify Python 3 is installed:This command will display the installed version (e.g.,bash
python3 --versionPython 3.12.xon Ubuntu 24.04). - Install
pip(Python package manager): This allows you to install other Python packages from the Python Package Index (PyPI).bashsudo apt install python3-pip - Install
venv(virtual environment module): This is crucial for creating isolated environments for your projects to manage dependencies without affecting the system Python.bashsudo apt install python3-venv - Create and activate a virtual environment:
- Create an environment in your project directory:bash
python3 -m venv my_project_env - Activate the environment:bash
source my_project_env/bin/activate
pythonandpipcommands within this environment (instead ofpython3andpip3). - Create an environment in your project directory:
Installing a Specific or Newer Python Version
If you need a different version not available in the default repositories, the recommended way is to use the
deadsnakes PPA (Personal Package Archive).- Add the
deadsnakesPPA:bashsudo add-apt-repository ppa:deadsnakes/ppa sudo apt update - Install the desired version (e.g., Python 3.14):bash
sudo apt install python3.14 - Verify the installation:bash
python3.14 --version
This version is installed alongside the system Python and can be accessed with its specific command (
python3.14). Always use virtual environments when working with these separate installations.
No comments:
Post a Comment