AD JB Toolbox 01 EN

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

  1. Download the macOS installer from python.org and check support for your macOS version and processor.
  2. Open the package, finish installation and open a new terminal.
  3. 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.

Create the shared practice folder and verify it

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.

More in This Category
Python Tutorial / Install Python on Windows and Verify the Interpreter

Python Tutorial / Install Python on Windows and Verify the Interpreter

Set up Python on Windows with the official Install Manager, create a project environment, and verify command resolution, versions and executable paths.

Python Tutorial / Build a First Program with Variables, Input and Output

Python Tutorial / Build a First Program with Variables, Input and Output

Read expense input, convert text to an integer and format a result. Understand assignment, comments, f-strings and the source of common conversion errors.

Python Tutorial / Set Up Python on macOS and Ubuntu

Python Tutorial / Set Up Python on macOS and Ubuntu

Prepare a Python development environment on macOS or Ubuntu without replacing system Python. Verify paths, create a virtual environment and test execution.

Python Tutorial / Create Virtual Environments and Manage Packages with pip

Python Tutorial / Create Virtual Environments and Manage Packages with pip

Use venv and python -m pip to separate projects, record dependencies and troubleshoot interpreter, package and activation problems.

Python Tutorial / What Is Python? Features and Practical Uses

Python Tutorial / What Is Python? Features and Practical Uses

Understand Python’s role, distinguish source files from the interpreter and terminal, and run a complete expense-total example with a small follow-up experiment.

Python Tutorial / Write and Run Python in VS Code

Python Tutorial / Write and Run Python in VS Code

Choose a virtual-environment interpreter in VS Code, run a complete Python script and use a breakpoint to check values while diagnosing environment mismatches.