How to Set Up a Python Environment for Beginners in 2026

Learning how to set up a Python environment for beginners takes about ten minutes and removes the single most common source of frustration in the language. You install Python once, create a folder called .venv inside your project, activate it, and install your packages there instead of on your whole machine. Everything after that just works: your code, your editor, and your teammate’s machine all agree on which packages you are using.

This guide covers Windows, macOS and Linux, with the exact command for each shell. Copy the blocks as they are, check the output after each step, and by the end you will have a project you can hand to someone else. Commands and version recommendations were last checked in 2026.

What You Need

A Python environment is an isolated folder holding its own copy of the interpreter, the standard library, and its own site-packages directory. Anything you install with pip while that folder is active lands inside it and nowhere else. That isolation is the whole point: one project’s dependencies cannot quietly break another’s.

Before you start, you need four things.

WhatWhy you need itWhere to get it
Python 3.11 or newerRuns your code. Every current tutorial assumes a recent release.python.org downloads page
A terminalCreates and activates the environment.Windows Terminal, PowerShell, macOS Terminal, or any Linux shell
A code editorWrites and runs your files.Visual Studio Code is the usual default; PyCharm works too
The venv moduleBuilds the isolated folder. It ships inside Python, so there is nothing extra to install.Already included

Two decisions cause most of the confusion online, so settle them now.

python.org or Anaconda? Install plain Python from python.org. The Anaconda-first advice you will still find in older tutorials was reasonable in 2016 and has since become a common source of the (base) prompt hijacking every terminal session. On r/learnpython the recurring guidance is to skip Anaconda, install from python.org, and use virtual environments. Miniconda earns its place when a project needs non-Python dependencies such as a specific GDAL or CUDA build; for a first Python setup it adds weight you will not use.

Global or isolated? A global install puts every package on your system interpreter. It works until you have two projects, one needing an old version of a library and one needing a new one. Then they cannot both be satisfied, and you are the one debugging it. Create one environment per project.

Which editor? Visual Studio Code is the sensible default: free, and the Python extension ships with an interpreter picker that finds your .venv folder automatically. PyCharm Community does the same job and costs nothing, and it configures the interpreter itself rather than making you choose. Whichever you pick, the important thing is that your editor and your terminal end up pointing at the same interpreter. They choose separately, and when they disagree you get a ModuleNotFoundError that makes no sense at the time.

Do you have to do this on your own machine? No. Google Colab, Replit and GitHub Codespaces all give you a Python environment in a browser tab with nothing to install, and they are genuinely useful for a first experiment or a quick data check. They are a poor home for real work: your files vanish when the session ends unless you download them, and you cannot point a colleague at the same setup. Set up the local version once and you have the same environment available offline, forever.

Step-by-Step: How to Set Up a Python Environment

Run every command from inside your project folder. The rest of the guide assumes that is where you are.

1. Check That Python Is Installed

Open a terminal and ask Python for its version.

# macOS and Linux
python3 --version

# Windows PowerShell or cmd
py --version

A healthy result looks like this.

Python 3.13.2

On macOS and Linux, python on its own sometimes points at an old system copy, which is why python3 is the safer command. Now confirm where Python actually lives.

# macOS and Linux
which python3

# Windows PowerShell or cmd
where.exe python

You should see a path inside your user folder or the install directory, not a bare hit to a WindowsApps stub or a system Python in /usr/bin. If you get command not found or “‘py’ is not recognized”, install Python from python.org first. On Windows, run the installer and tick Add python.exe to PATH on the first screen, then reopen your terminal.

2. Create a Project Folder

Give the project its own directory so the environment, the script, and the data stay together.

# macOS and Linux
mkdir ~/projects/census-check
cd ~/projects/census-check

# Windows PowerShell or cmd
mkdir $HOMEprojectscensus-check
cd $HOMEprojectscensus-check

A healthy project folder looks like this once you are done.

census-check/
├── .venv/          <- the environment; never committed to git
├── data/           <- CSVs or JSON you downloaded
├── analysis.py     <- your script
├── requirements.txt
└── .gitignore

Keep the folder name free of spaces and keep it out of anything like Program Files. Windows paths with spaces and deep system directories are a reliable cause of venv creation failures.

The .venv name is a convention, not a requirement. You can call it env, myenv or anything else, and python -m venv myenv works just as well. Stick with .venv anyway, because editors, deployment tools and .gitignore templates recognise that name by default. If you do use a different name, remember that the activation command has to match it exactly.

3. Create a Virtual Environment

From inside the project folder, run the venv module that came with Python.

# macOS and Linux
python3 -m venv .venv

# Windows PowerShell or cmd
py -m venv .venv

Use python -m venv rather than plain venv so the environment is built by the interpreter you just verified. The command prints nothing when it succeeds. That silence is normal.

On macOS and Linux the files land in .venv/bin and .venv/lib; on Windows in .venvScripts and .venvLib. You never open these folders by hand. Check that it worked like this.

ls .venv                    # macOS and Linux
dir .venv                    # Windows cmd

One warning about the Windows installer: leave Install launcher for all users unchecked unless you need it. The py launcher is the most reliable way to reach a specific Python on Windows, and a machine-wide launcher plus a user-level one occasionally resolves to the wrong interpreter.

There is a second tool called virtualenv, which is not the same thing. It is a third-party package that can target older Python versions, and on any modern setup the built-in venv module does everything it does. Reach for it only if you are supporting Python versions older than 3.3, which almost nobody is. The same goes for Pipenv and for Astral’s uv: both are faster and popular on developer teams, and neither is where a beginner should start.

4. Activate the Virtual Environment

Activation does not install anything. It points your shell’s PATH at the folder so that python and pip resolve to the copies inside it.

# macOS and Linux (bash, zsh)
source .venv/bin/activate

# Windows PowerShell
..venvScriptsActivate.ps1

# Windows cmd
.venvScriptsactivate.bat

Your prompt should change. This is the whole visual confirmation that it worked.

# before
census-check $

# after
(.venv) census-check $

If PowerShell refuses with something like “cannot be loaded because running scripts is disabled on this system”, the error is about Windows script policy, not Python. Allow scripts for your own user account, then retry the activation command.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

You are asked to confirm once, choose Yes, then run the activation command again. Leave and re-enter the environment whenever you switch projects.

deactivate

5. Install and Inspect Packages

With the (.venv) prefix in your prompt, install into the environment.

# macOS and Linux
python3 -m pip install requests

# Windows
py -m pip install requests

Prefer python -m pip over a bare pip: it guarantees the package goes to the same interpreter running your script. Packages come from PyPI, the Python Package Index, which is a public registry of more than half a million projects. Install by name for everyday work, and pin a version when a project, a tutorial or a collaborator depends on a specific one.

python3 -m pip install "pandas==2.2.3"

See what is installed, or remove something that misbehaves.

python3 -m pip list
python3 -m pip uninstall requests

Installing before activating is the most common ordering mistake. If you run pip install with no (.venv) in the prompt, the package lands in your global Python and your project still cannot see it.

6. Run a Test Python File

Create analysis.py in the project folder with this content.

import sys
import requests

print("Python:", sys.executable)
print("requests:", requests.__version__)

Run it from the same folder.

python3 analysis.py

Three things just proved themselves at once. The interpreter path printed by sys.executable points inside .venv, so your terminal is using the environment. The version line shows the package resolved from the environment’s site-packages. And the script ran at all, so your PATH and folder are right.

Running the same file from your editor is the last piece. In VS Code open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS), run Python: Select Interpreter, and choose the entry that contains .venv. If no environment is listed, open the folder itself in VS Code first, since the extension only searches inside the open project. A new integrated terminal created after that choice inherits the environment, and its prompt should show (.venv). In PyCharm the equivalent is Settings, Project, Python Interpreter, where the .venv folder usually appears already detected.

7. Save the Project Requirements

Capture the exact package list so the project can be rebuilt on another machine.

# macOS and Linux
python3 -m pip freeze > requirements.txt

# Windows PowerShell
py -m pip freeze | Out-File -Encoding utf8 requirements.txt

# Windows cmd
py -m pip freeze > requirements.txt

PowerShell’s default redirection writes UTF-16, which pip cannot read, so the Out-File -Encoding utf8 form matters there.

requests==2.32.3
pandas==2.2.3
certifi==2024.8.30

On any machine, with the environment active, recreate the whole setup in one command.

python3 -m pip install -r requirements.txt

Add a .gitignore so the environment never lands in version control. Committing .venv is a recurring and expensive mistake: it adds thousands of machine-specific files and breaks checkouts on other people’s machines.

.venv/
__pycache__/
*.pyc

Common Mistakes

Almost every beginner problem with Python environments shows a symptom that could mean four different things. Match the text on your screen against this table first.

SymptomCauseFix
ModuleNotFoundError: No module named 'requests' right after a successful pip installThe editor is running a different interpreter than your terminalIn VS Code press Ctrl+Shift+P, run Python: Select Interpreter, and pick the one inside .venv. Then reopen the terminal
ModuleNotFoundError and no (.venv) in the promptYou installed before activating, or in the wrong folderActivate the environment, confirm the prompt prefix, then reinstall the package
PowerShell: scripts are disabled on this systemThe default execution policy blocks the activation scriptSet-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser, then activate again
(base) sits in every prompt and breaks scripts that read terminal outputAnaconda auto-activates its base environment on startupRun conda config --set auto_activate_base false, or remove the Anaconda block from your shell profile
Command not found in your new folderTerminal is in the wrong directorypwd to check, then cd into the project folder and rerun
pip installs but the script still cannot importpip and python resolve to different installationsAlways use python -m pip install ... so both point at one interpreter
Packages behave oddly after installing with condaconda and venv environments are separate systems and do not mixPick one per project. If the project is conda-based, use conda to install too
Notebook cells fail while the terminal worksThe Jupyter kernel is bound to a different environmentIn the notebook, choose Kernel, then Select Another Kernel, and pick your .venv interpreter
Environment works locally but a package fails on a serverThe package was never written to requirements.txtRe-run python -m pip freeze > requirements.txt and commit the file

When an environment is genuinely wrecked, deleting it is safe and fast. Nothing in it matters except the packages, and those live in requirements.txt.

# macOS and Linux
rm -rf .venv

# Windows PowerShell or cmd
rmdir /s /q .venv

Then repeat steps 3 and 4 and run python -m pip install -r requirements.txt. On Windows, close editors and terminals that still have the folder open first, or the delete will complain that the file is in use.

Two related questions come up at this point. Is it safe to delete .venv? Yes. It holds copies, not originals: your script and your requirements file live outside it, and rebuilding takes under a minute. Some people keep environments outside the project folder so several projects can share one; that works, but it removes the main advantage, since the project is no longer self-contained and the activation command has to use an absolute path.

And how do you use two projects at once? Keep one environment per project and switch by activating the one belonging to the folder you are in. With (.venv) already active from another folder, activating a different environment simply replaces the PATH, so you can flip between them as often as you like. The one rule: check the prompt prefix before you install anything, because a package installed into the wrong environment is the reason a colleague’s project will not run on your machine.

How to Tell Your Python Environment Is Working

Run this five-point check whenever something feels off. It takes about fifteen seconds and tells you which layer broke.

  1. The prompt shows the prefix. (.venv) before your folder name means activation succeeded.
  2. The interpreter path is inside the project. python -c "import sys; print(sys.executable)" should print a path containing .venv.
  3. Imports resolve. python -c "import requests; print(requests.__version__)" should print a version number rather than an error.
  4. A script runs from the command line. python analysis.py should print the two lines from step 6.
  5. The requirements file matches the environment. python -m pip freeze should list every package your script imports.

If points one and two pass but three or four fail, the environment is fine and the script is wrong. If one fails but the rest pass, you are running the file outside the environment. If one and two fail, the environment was never activated or was deleted.

Frequently Asked Questions

Do I need a virtual environment if I am just learning Python?

Yes, and it gets easier after the first ten minutes. Even learning projects pick up libraries, and installing those globally is how people end up unable to upgrade a tool later. One python -m venv .venv per folder costs you two extra commands and makes every later package install undoable by deleting one directory.

How do I deactivate a Python environment?

Type deactivate and press Enter. The (.venv) prefix disappears from your prompt and your shell goes back to the system Python. You can also just close the terminal window, since each new terminal session starts fresh with no environment active.

Should beginners use conda or is venv enough?

venv is enough for almost everything. It ships with Python, takes no extra install, and creates an isolated folder in a couple of seconds. conda earns its place when your project depends on non-Python libraries, such as a specific GDAL, GPU or CUDA build. Mixing conda and venv installs in one project causes confusion, so pick one per project.

What should I commit to version control in a Python project?

Commit your code, your data files, your requirements.txt and your .gitignore. Never commit the .venv folder or __pycache__. The environment contains thousands of machine-specific files that differ on every operating system, and committing them breaks checkouts for everyone else on the team.

Why is my package not found after pip install?

In most cases your editor is using a different Python than your terminal. Terminals and editors pick interpreters separately, and VS Code will happily keep using an older one. Run python -m pip install name instead of a bare pip, confirm python -c “import sys; print(sys.executable)” points inside .venv, then select that same interpreter in the editor’s interpreter picker.

Which Python version should I install?

Install a current stable release from python.org, which is in the 3.11 to 3.13 range. Avoid whatever version your operating system happens to ship, since those are often years behind and rarely receive security fixes. Avoid tutorials pinned to 3.6 or 3.8 as well; most modern packages have dropped support for them.

Conclusion

Create one project folder, run python -m venv .venv, activate it with the command for your shell, install the one package you actually need, and prove it with a two-line script that prints sys.executable. When that path points inside .venv, your Python environment setup is done and everything else is ordinary work. Save requirements.txt at the end of the session and the setup travels with the project to any other machine.

Leave a Comment