How to Install Python: A Safe Setup Guide
Install a current Python release on Windows, macOS, or Linux; prove which interpreter and pip you are using; create an isolated project environment; and fix the common setup failures without damaging your system Python.
Install Python only from python.org, the official Windows Install Manager, or your Linux distribution’s package manager. Open a new terminal and verify the interpreter path, version, and its paired pip. Then create a .venv inside every project and install packages through that project interpreter—not through a bare global pip command.
Before you install: decide what you actually need
For learning, web projects, automation, and most new applications, choose the latest stable Python release that your project’s dependencies support. Do not install a preview release just because it is newer. If you are joining an existing project, read its pyproject.toml, requirements file, README, CI configuration, or team instructions first: the project may require a specific Python minor version.
| Situation | Recommended choice | Why |
|---|---|---|
| You are new to Python | The official installer or install manager | It gives you a supported interpreter and the normal tools without changing system-managed files. |
| You are on Windows with multiple Python versions | Use py to list and select versions | The launcher/install manager makes the selected interpreter explicit. |
| You are on macOS | Use python3 for terminal commands | It avoids ambiguity with any system-provided Python command. |
| You are on Linux | Use your distribution package manager for the base interpreter | The distribution owns system Python and its dependencies; leave that foundation intact. |
| You are joining a project | Match the project’s documented version, then create .venv | A project environment is more important than a single machine-wide default. |
Have this ready
- A new terminal window you can close and reopen after installation.
- Enough disk space and permission to install software for your account.
- The Python version required by an existing project, if you have one.
- An editor that can select a project interpreter, such as VS Code, PyCharm, or another environment-aware editor.
Install Python from a trusted source
Use the operating-system tab that matches your computer. The goal is not only to finish an installer: it is to know exactly which command launches Python, where it lives, and which pip belongs to it.
- 01
Install through the official Windows path
Use the Microsoft Store, WinGet, or the official Python download page. Current Python documentation describes the Python Install Manager as the supported way to install and manage Python runtimes on modern Windows.
- 02
Open a brand-new PowerShell window
Do not test in a terminal that was already open during installation; it may still have the old PATH and aliases.
- 03
Ask the launcher what is installed
Run py list. If more than one runtime exists, this shows the available versions before you create a project environment.
- 04
Use py -m pip, not a detached pip command
This connects pip to the exact Python selected by py. When a project demands a particular version, use that version consistently before creating .venv.
py list
py --version
py -m pip --version
py -c "import sys; print(sys.executable)"Prove which Python will run your code
A version number alone is not enough. Machines often have several Python installations, and a bare pip command can point to a different one. Verify the interpreter executable and ask that same interpreter to run pip. These four facts must agree: the command you type, the version, the executable path, and the package installer.
py -c "import sys; print(sys.version); print(sys.executable)"
py -m pip --version| Output | What it proves | What to do if it is wrong |
|---|---|---|
| A Python 3 version you expect | The command found a Python interpreter. | Use the project-required command or install the required supported version. |
| An executable path you recognize | You know which installation will execute your code. | Check command -v / where and shell aliases before installing packages. |
| pip mentions the same Python version/path family | pip is paired with the interpreter you verified. | Use python -m pip or py -m pip every time. |
| No command found | The terminal cannot locate the interpreter. | Open a new terminal; then use py on Windows or inspect your installation/PATH on macOS and Linux. |
Create an isolated project environment
A virtual environment is a directory containing a project-specific interpreter and package location. It prevents one project’s dependencies from silently changing another project or your operating system. Put it inside the project as .venv so editors can discover it and so it is easy to delete and recreate.
mkdir hello-python
cd hello-python
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -c "import sys; print(sys.executable)"- 01
Create the project directory
Keep project source, its dependency files, and .venv together. Do not create a virtual environment in a random global folder and reuse it for unrelated applications.
- 02
Create .venv with the interpreter you verified
Use py -m venv .venv on Windows or python3 -m venv .venv on macOS/Linux. The base interpreter chosen here determines the environment version.
- 03
Activate it only for convenience
Activation changes your current shell so python and pip resolve to .venv. It is not required: .venv/Scripts/python or .venv/bin/python can be called directly in scripts and CI.
- 04
Check sys.executable after activation
It should point inside the project’s .venv directory. If it does not, stop before installing packages; you are using the wrong interpreter.
import sys
print("Python is ready.")
print(f"Running: {sys.executable}")python hello.py
python -m pip install --upgrade pip
python -m pip install requests
python -m pip show requestsInstall packages without losing the interpreter
The safest package command is always interpreter -m pip. It asks the exact interpreter that will run your code to install or inspect its packages. This avoids the most common beginner failure: python runs one installation while pip writes to another.
python -m pip --version
python -m pip install requests
python -m pip show requests
python -c 'import requests; print(requests.__version__)'- Use py -m pip in a Windows shell before .venv is active; after activation, python -m pip is usually clearest.
- Use python3 -m pip before activation on macOS/Linux; after activation, python -m pip refers to .venv.
- Do not use sudo pip or sudo python -m pip for project dependencies.
- Do not install every package globally 'for later'. Add a dependency only inside the project that uses it.
- If a project supplies requirements.txt or pyproject.toml, follow that project’s install command rather than inventing a different dependency format.
Troubleshoot the failure, not the symptom
| Problem | Likely cause | Safe next step |
|---|---|---|
| python is not recognized | The terminal was opened before installation, PATH is not configured, or the command is not the one your OS uses. | Open a new terminal. Try py on Windows; try python3 on macOS/Linux; then inspect the executable path. |
| py works but python does not on Windows | The launcher/install manager is installed but the global python alias/PATH is not configured. | Use py consistently, or configure PATH only if you need python as a direct command. |
| pip installs to the wrong place | A bare pip resolved to a different installation than Python. | Compare python -c 'import sys; print(sys.executable)' with python -m pip --version, then use interpreter -m pip. |
| venv is unavailable on Linux | Your distribution may package virtual-environment support separately. | Install the venv package named by your distribution documentation, then rerun python3 -m venv --help. |
| Activate.ps1 is blocked | PowerShell execution policy blocks scripts. | Read the policy message and use the least-permissive organization-approved solution; direct .venv interpreter paths are an alternative. |
| An editor uses a different Python | The editor selected a global interpreter or cached an old environment. | Select the project’s .venv interpreter explicitly, reload the editor window, then print sys.executable from its integrated terminal. |
| ModuleNotFoundError after installation | The package was installed in another environment or the environment is not active. | Run python -m pip show package-name and python -c 'import package_name' from the same terminal. |
Reset a broken project environment safely
A virtual environment is disposable. If it points to the wrong Python, has inconsistent packages, or cannot be repaired quickly, remove only that project’s .venv directory, recreate it with the intended interpreter, and reinstall from the project’s tracked dependency file. Never delete a system Python directory to fix a project environment.
# Deactivate first if the environment is active
deactivate
# Remove only this project's .venv directory using your file manager or shell
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txtFinish with a setup you can trust
Your Python foundation is ready when
- You can state which Python version your project requires and why.
- A terminal command shows a Python executable path inside .venv for the project.
- python -m pip --version points into the same environment family.
- Your editor has selected the .venv interpreter.
- A small hello.py file runs from the terminal and editor.
- .venv/ is ignored by Git while project dependency declarations are tracked.
- You know how to recreate .venv rather than trying to repair system Python.
Next, learn the language before adding frameworks. Start with values, types, control flow, functions, files, and exceptions. Once that foundation is comfortable, build a small project and add dependencies one at a time with the environment already working.
Frequently asked questions
Which Python version should I install?
For a new personal project, choose the current stable release supported by the packages you expect to use. For an existing repository, use the exact version range documented by that project or its CI configuration. Avoid preview releases unless the project explicitly needs one.
Should I use python, python3, or py?
Use the command that reliably identifies the interpreter you verified. On Windows, py is useful for listing and selecting installed versions. On macOS and Linux, python3 is the clear global command. Inside an activated .venv, python normally points to that environment.
Why use python -m pip?
It runs pip through the same interpreter that will execute your application. This avoids installing a package into one Python installation and then trying to import it from another.
Do I need to activate .venv?
No. Activation is a convenience that changes shell command resolution. You can always invoke the environment interpreter directly, such as .venv/bin/python on macOS/Linux or .venv\Scripts\python.exe on Windows. CI commonly uses direct paths or tool-managed environments.
Can I delete .venv?
Yes. A project virtual environment is designed to be recreated. Delete only the project’s .venv directory, then recreate it with the intended Python and reinstall from the project’s tracked dependency declaration.
Why should I avoid sudo pip?
It can overwrite packages owned by the operating system or create permissions that later block normal project work. Use a project virtual environment instead; system package managers should manage system Python packages.