Python Tutorial / Set Up Python on macOS and Ubuntu
On macOS and Ubuntu, start by checking the version and path of python3, then create a project-specific virtual environment. Keep your development environment separate from the Python installation used by the operating system.
Identify the existing interpreter
python3 --version command -v python3 python3 -c "import sys; print(sys.executable)"
Record which installation owns the reported path. These lessons target Python 3.12 or later. If the command is missing or older than the required version, obtain a development interpreter through a supported method for your operating system. Replacing the /usr/bin/python3 symlink can disrupt system tools.
For the relevant APIs and platform requirements, see Set Up Python on macOS and Ubuntu documentation.
Use the official macOS installer
- Download the macOS installer from python.org and check support for your macOS version and processor.
- Open the package, finish installation and open a new terminal.
- Check python3 again. If multiple installations exist, use the full path of the intended executable when creating the virtual environment.
If HTTPS requests fail because of certificates, follow the certificate installation instructions supplied with the official installer. Disabling certificate verification prevents the program from authenticating the remote endpoint and does not fix the underlying trust configuration.
Install distribution packages on Ubuntu
The following commands use Ubuntu’s Python, venv and pip packages. The provided Python version depends on the Ubuntu release. Check the version afterwards; choose a supported release or a separate development environment if it does not meet the lesson requirements.
sudo apt update sudo apt install python3 python3-venv python3-pip python3 --version
An externally-managed-environment message can mean that package installation belongs in a virtual environment. Do not work around that separation with sudo pip or by disabling system protections.
mkdir python-lab cd python-lab python3 -m venv .venv .venv/bin/python --version .venv/bin/python -m pip --version .venv/bin/python -c "print(3500 + 8000 + 2500)"
The final command should print 14000. To activate the environment, run source .venv/bin/activate; leave it with deactivate. Activation changes command lookup in the current shell. You can also call .venv/bin/python directly, as shown.
If venv creation fails, check for venv support matching the chosen interpreter. Keep scripts in python-lab outside .venv so that recreating the environment does not remove your work. The package management lesson explains how to record and reinstall dependencies.






