PythonIntroduction to PythonPython environment setup
How do you install Python on a computer?
Question 14 of 20 · Updated
On this page
- 1. What do you need before installing Python?
- 2. Which Python version should you install?
- 3. How to install Python on Windows
- Step 1: Open the official download page
- Step 2: Install the Python interpreter
- Step 3: Verify the installation
- 4. How to install Python on macOS
- Option A: Official Python installer
- Option B: Homebrew
- 5. How to install Python on Linux
- Ubuntu and Debian
- Fedora
- Arch Linux
- 6. What is the difference between installing Python and configuring PATH?
- 7. How do you verify that Python and pip work?
- 8. How do you run your first Python program?
- 9. What should you do after installation?
- 10. Which installation method should you choose?
- 11. Common installation mistakes and troubleshooting
- Python is not recognised as a command
- Windows opens the Microsoft Store instead of Python
- The Python version is not the one you expected
- pip is missing or points to another Python installation
- venv fails on Linux
- An installer is incompatible with your operating system
- A script fails even though Python is installed
- 12. Best practices for a reliable Python installation
- 13. Frequently asked questions
- Is Python free to install?
- Do I need to install pip separately?
- Can I install more than one Python version?
- Do I need VS Code or PyCharm to install Python?
- Is Python installation the same as creating a virtual environment?
- 14. Interview-ready answer
- Key takeaways
- Official references
To install Python on a computer, choose a supported Python 3 release, obtain it from an official or trusted distribution channel, install the interpreter for your operating system, and verify that you can run Python from a terminal. You can then create a simple Python file to confirm the installation works.
The exact installer, menu labels and commands depend on your operating system and Python distribution. This guide covers Windows, macOS and Linux without assuming that every computer uses the same installer.
1. What do you need before installing Python?#
Python is free to download and use. For a typical development setup, you need:
- A supported operating system and a Python release compatible with it.
- Permission to install software on your computer, or a user-level installation method if administrative access is restricted.
- A terminal such as PowerShell on Windows or Terminal on macOS and Linux.
- An internet connection to download the installer or obtain packages from a trusted package repository.
You do not need an IDE, compiler or third-party Python package just to run a basic Python program. The standard Python installation includes an interpreter and the standard library. Most official desktop distributions also provide pip and support for creating virtual environments; some Linux distributions package these components separately.
2. Which Python version should you install?#
For a new project, choose a supported, stable Python 3 release that your operating system and required libraries support. The official Python downloads page lists available releases, and the Python Developer's Guide describes their support status.
Avoid choosing a prerelease for a beginner or production environment unless you specifically need to test upcoming features. Python 2 is no longer officially supported and should not be the default for new projects.
For an existing project, check its README, dependency configuration and CI settings before choosing a version. For example, a project may require Python 3.12 even if a newer stable release is available. Installing a version that the project's dependencies do not support can cause package installation failures.
Choose an installer appropriate for your processor architecture, such as x86-64 or ARM64, where the distributor offers that choice.
3. How to install Python on Windows#
Step 1: Open the official download page#
Visit python.org/downloads/windows/ or follow the Windows installation instructions in the official Python documentation. Choose the installation method appropriate for your Windows version and the Python release you need.
Depending on the release, the recommended method may use the Python Install Manager or a traditional executable installer. The workflows are different, so follow the instructions shown for the installer you actually download.
Step 2: Install the Python interpreter#
With a traditional Python installer:
- Open the downloaded installer.
- If it offers Add Python to PATH, enable that option when you want to use the python command from the terminal.
- Choose the standard installation, or customise it if your project requires a different location or optional components.
- Complete the installation.
If the official download page directs you to the Python Install Manager, install the manager and follow its documented workflow to obtain the Python runtime. For example, where the manager supports the command, use a version-specific installation such as:
POWERSHELLpy install 3.13
Here 3.13 is an illustrative version, not a claim about the newest release. Choose a supported version appropriate for your project. The py install subcommand is specific to the install manager; the older Windows Python launcher does not implement it.
On a managed corporate computer, use the approved installation method. Do not bypass administrator or organisational restrictions.
Step 3: Verify the installation#
Close and reopen PowerShell or Command Prompt so it picks up any environment changes. Try:
POWERSHELLpython --version
If your installation provides the py command, you can also try:
POWERSHELLpy --version
A working Python 3 installation returns a version such as:
Python 3.13.5The exact number on your machine will depend on the installed release. Both commands need not be available on every Windows installation.
To inspect the actual Python executable, use:
POWERSHELLpython -c "import sys; print(sys.executable)"
Or, if using py:
POWERSHELLpy -c "import sys; print(sys.executable)"
These commands reveal the interpreter selected by that invocation. They are more informative than merely checking that a command exists.
4. How to install Python on macOS#
Option A: Official Python installer#
- Visit python.org/downloads/macos/.
- Select a compatible Python 3 release and the macOS installer offered for your computer.
- Open the downloaded package and follow the installation wizard.
- Open a new Terminal window and verify the installation.
BASHpython3 --version python3 -c "import sys; print(sys.executable)"
Use the installer-specific instructions included with the download. For example, some official macOS installations provide a certificate setup command or script. Follow the distributor's instructions if HTTPS certificate verification needs configuration; do not disable certificate verification as a workaround.
Option B: Homebrew#
If Homebrew is already installed and approved for your machine, you can use it to install Python:
BASHbrew install python python3 --version
Homebrew manages its own Python packages and updates. If a command is not found, follow the Homebrew setup instructions for your shell and architecture.
Do not assume that the system-provided Python, a Python.org installation and a Homebrew installation are interchangeable. They may have different versions, paths and package directories. Use the interpreter you intend to run and keep its project dependencies isolated.
5. How to install Python on Linux#
Many Linux distributions already include Python 3 because system utilities depend on it. Check first:
BASHpython3 --version
If you need Python or additional development components, use your distribution's trusted package manager.
Ubuntu and Debian#
BASHsudo apt update sudo apt install python3 python3-venv python3-pip
This installs the distribution-provided Python interpreter and, where available, packages for virtual environments and pip. Package availability and Python versions depend on the distribution release.
Fedora#
BASHsudo dnf install python3 python3-pip
Verify that the installed interpreter supports venv before using it. If a component is missing, consult the distribution's package documentation.
Arch Linux#
BASHsudo pacman -Syu python python-pip
Arch uses a rolling-release model. The command above performs a system upgrade as part of installing these packages; review the changes before approving them and follow your distribution's upgrade guidance.
After installing Python, run:
BASHpython3 --version
Important: Do not remove or replace the operating system's Python interpreter merely to obtain a newer version. System tools can depend on its exact installation. If a project needs another Python version, install it alongside the system interpreter using a supported version-management or distribution method.
6. What is the difference between installing Python and configuring PATH?#
Installing Python places an interpreter and supporting files on your computer. PATH is an environment variable containing directories that your shell searches when you type an executable command.
These are separate operations. Python can be installed correctly even when the terminal cannot find the python or python3 command.
| Concept | Purpose |
|---|---|
| Python interpreter | Executes Python programs |
| Installer or package manager | Installs and maintains the interpreter |
| PATH | Helps a terminal locate executable commands |
| pip | Installs Python packages into a selected environment |
| IDE or editor | Helps you write, run and debug code |
| Virtual environment | Isolates project-level Python dependencies |
On Windows PowerShell, inspect available commands with:
POWERSHELLGet-Command python, py -ErrorAction SilentlyContinue
On macOS and Linux, use:
BASHcommand -v python3
These commands show how the shell resolves a command. The Python-level sys.executable check shows the actual running interpreter.
A shortcut, alias or application execution alias can resolve differently from a normal executable. When there are multiple installations, check both the version and the interpreter path rather than making assumptions from the command name.
7. How do you verify that Python and pip work?#
A version check confirms that an interpreter starts, but a small program gives stronger evidence that it can execute code.
On macOS or Linux:
BASHpython3 -c "import sys; print(sys.version_info.major == 3)"
On Windows, substitute python or py according to your installation.
Expected output for Python 3:
TrueNext, check whether pip is available for that interpreter:
BASHpython3 -m pip --version
On Windows:
POWERSHELLpython -m pip --version
Or:
POWERSHELLpy -m pip --version
The output reports the pip version, its installation location and the associated Python version. These values vary by computer.
Using python -m pip (or python3 -m pip) is usually safer than using a bare pip command when multiple interpreters are installed because it explicitly invokes pip through the selected interpreter.
If pip is missing, consult the installation method's instructions. Official Python distributions often include it, but operating-system-managed Python installations may require a separate package. Do not automatically use administrator privileges to install third-party Python packages.
8. How do you run your first Python program?#
Open a text editor and save a file named hello.py with the following content:
PYTHONprint("Hello, Python!")
Open a terminal in the directory containing hello.py.
Windows
POWERSHELLpython hello.py
Alternatively, if the py command is available:
POWERSHELLpy hello.py
macOS or Linux
BASHpython3 hello.py
Expected output:
Hello, Python!The interpreter reads and executes the file. If you see the expected output, you have confirmed that Python can run a script.
You can also verify the standard library without installing an external package:
PYTHONimport math print(math.isqrt(81))
Expected output:
9Save this example in a Python file or enter it in an interactive Python session. The math module is part of the standard library; it does not require pip installation.
9. What should you do after installation?#
For development projects, create a separate virtual environment rather than installing all libraries into a global Python installation.
For example, on macOS and Linux:
BASHpython3 -m venv .venv source .venv/bin/activate
On Windows PowerShell, using an available Python command:
POWERSHELLpython -m venv .venv .\.venv\Scripts\Activate.ps1
If PowerShell restricts script execution, activation is optional. You can invoke the virtual environment's Python executable directly without changing system security settings.
Verify the active interpreter:
PYTHONimport sys print(sys.prefix != sys.base_prefix)
Expected output when running in a standard virtual environment:
TrueThis is a brief installation follow-up. Creating, activating and managing environments is covered separately in the Python environment lesson.
10. Which installation method should you choose?#
| Method | Best suited for | Considerations |
|---|---|---|
| Official Python Windows installer or Install Manager | General Windows development | Choose the documented workflow for the release and confirm command availability |
| Official Python macOS package | General macOS development | Follow the installer-specific setup guidance |
| Homebrew | macOS developers already using Homebrew | Package updates and paths are managed by Homebrew |
| Linux package manager | System-compatible Linux development | Available Python versions depend on distribution release |
| Version manager or Conda | Projects with specific Python versions or environment requirements | Requires additional tooling and explicit environment management |
There is no universal best installation method. Prefer a trusted channel that fits your operating system, project dependencies and maintenance requirements.
11. Common installation mistakes and troubleshooting#
Python is not recognised as a command#
Open a new terminal. Check whether Python is installed and whether the expected command is available. On Windows, try python and py as appropriate. On macOS or Linux, try python3. If necessary, follow your distribution's documented PATH configuration steps. Avoid blindly adding unrelated directories to PATH.
Windows opens the Microsoft Store instead of Python#
Windows may resolve a python command to an application execution alias rather than the interpreter you installed. Inspect command resolution, check the official installer or install manager's configuration, and adjust the relevant Windows app execution aliases if appropriate. Verify with sys.executable afterward.
The Python version is not the one you expected#
Multiple installations may be present. Check the executable path and version for each relevant command. Select the correct interpreter in your editor and create the virtual environment from that interpreter.
pip is missing or points to another Python installation#
Use the selected interpreter's -m pip --version command. If pip is absent, install the appropriate pip component according to the installation channel. Avoid modifying operating-system-managed Python packages globally; use a virtual environment when installing project dependencies.
venv fails on Linux#
Some distributions provide virtual environment support as a separate package. On Debian or Ubuntu, check whether the appropriate python3-venv or version-specific venv package is installed. Ensure the package corresponds to the interpreter you are using.
An installer is incompatible with your operating system#
Confirm the operating system version, processor architecture and Python release requirements. Choose a compatible supported distribution instead of forcing an incompatible package to install.
A script fails even though Python is installed#
A successful version check does not guarantee that every script is correct. Check the current directory, filename, file extension, syntax and required dependencies. If the interpreter displays a Python traceback, the interpreter is running; the error may be in the program or its environment.
12. Best practices for a reliable Python installation#
- Use python.org, an approved operating-system repository or another trusted distribution channel.
- Choose a supported Python 3 release compatible with your project.
- Verify the interpreter version and path after installing.
- Keep the system Python intact on Linux and macOS.
- Use virtual environments for application dependencies.
- Select the same interpreter in your terminal, editor and test tools.
- Document the Python version required by a shared project and keep dependency specifications under version control.
These steps reduce environment-specific failures when a project moves between a developer's computer, a CI runner and a production server.
13. Frequently asked questions#
Is Python free to install?#
Yes. Python is open-source software and can be downloaded and used without purchasing a Python licence.
Do I need to install pip separately?#
Not always. Many official Python distributions include pip. Some Linux distributions provide it separately. Verify it with the selected interpreter's -m pip --version command.
Can I install more than one Python version?#
Yes. Multiple versions can coexist if they are installed using compatible methods and selected explicitly. Check the interpreter path before creating a virtual environment or installing dependencies.
Do I need VS Code or PyCharm to install Python?#
No. Python can be installed and used from a terminal without an IDE. Editors are optional tools for development.
Is Python installation the same as creating a virtual environment?#
No. Installing Python provides the base interpreter. A virtual environment is a project-specific environment created using an existing interpreter.
14. Interview-ready answer#
To install Python, download a supported Python 3 release from an official or trusted distribution channel, or use your operating system's package manager. On Windows, follow the appropriate Python installer or install manager workflow; on macOS, use the official package or an approved package manager; on Linux, use the distribution package manager without replacing system Python. Verify the installation using python --version, python3 --version or py --version as appropriate, inspect the interpreter path, and run a simple Python script. For development, create an isolated virtual environment for project dependencies.
Key takeaways#
- Installing Python provides the interpreter needed to run Python programs.
- Choose a supported release and a trusted installation method for your operating system.
- A successful version check, interpreter-path check and first script confirm the basic setup.
- Installing Python and creating a virtual environment are related but separate tasks.
- Avoid replacing system interpreters or weakening security controls to solve installation problems.
Official references#
- Python downloads
- Using Python on Windows
- Using Python on macOS
- Using Python on Unix platforms
- Python version support status
- Python documentation: venv
Verification note: The interpreter checks, first program, math example and virtual-environment smoke test were exercised locally using Python 3.13.5. Platform-specific installation procedures were described from established knowledge; live documentation and installer behaviour were not independently checked. Consult the linked official documentation for current release-specific instructions.
References
- 1.Python.org — Download Pythonpython.org
- 2.Python Documentation — Using Python on Windowsdocs.python.org
- 3.Python Documentation — Using Python on macOSdocs.python.org
- 4.Python Documentation — Using Python on Unix platformsdocs.python.org
- 5.Python Developer's Guide — Status of Python versionsdevguide.python.org
- 6.Python Documentation — venvdocs.python.org
Related questions
Explore other topics:Forward Deployed EngineeringMachine LearningSQL: Structured Query LanguageAI System Design