Set Up Python on Your Computer
Install Python on Windows, macOS or Linux, install VS Code, run your first .py file, use the terminal, install packages with pip inside a virtual environment, open Jupyter notebooks, and fix the problems almost everyone meets.
Do you need this yet?
Not to learn: every lesson runs in your browser. But every real project, job and university assignment runs Python on a computer, so you will need it sooner or later. It takes about 20–30 minutes. You can do it now, or come back after the Loops lesson.
You will install two things:
- Python itself: the program that reads and runs your code (called the interpreter).
- VS Code: a free editor, a program for writing code, like a word processor for programs. It colours your code, spots mistakes and has a Run button.
Using a Chromebook, a tablet or a locked work computer?
Use Google Colab ↗: free Python notebooks in the browser with a Google account, nothing to install. It is what many AI courses use, and it has free GPUs for deep learning later.
Step 1: install Python
Choose your computer. Use Python 3.12 or newer; any recent version is fine. Do not use Python 2, which is obsolete.
- Open the Microsoft Store, search for Python install manager, and press Install. (It is also on python.org/downloads/windows ↗.) This is the method python.org recommends for Windows.
- Close any open terminal windows. Press the Windows key, type Terminal (or PowerShell), and open it.
- Type this and press Enter. The first time, it may ask a few setup questions: accept the suggested answers.
If you see a version number, Python is installed. On Windows you start Python with py (and usually python works too).
Older guides tell you to download a .exe installer and tick "Add python.exe to PATH". That still works, but python.org is retiring that installer, so use the install manager for new setups.
- Go to python.org/downloads/macos ↗ and download the latest macOS 64-bit universal installer. Open it and click through.
- Open the Terminal app (press ⌘ + Space and type Terminal).
- Check it worked:
On a Mac, always type python3 and pip3, not python. The plain python command may not exist, or may be an old copy Apple uses for itself.
If you already use Homebrew, brew install python works too.
Most Linux systems already have Python 3. Open a terminal and check:
On Ubuntu or Debian, also install the tools for virtual environments and packages:
Use python3 and pip3 (inside a virtual environment, plain python and pip work). Never remove or replace the system Python: Linux uses it for itself.
Step 2: install VS Code
- Download Visual Studio Code from code.visualstudio.com ↗ and install it (on Windows, tick "Add to PATH" if asked).
- Open VS Code. Click the Extensions icon on the left (four small squares), search for Python, and install the one published by Microsoft. It also installs Pylance, which spots mistakes as you type.
Other good editors exist (PyCharm, or Jupyter for notebooks), but VS Code is free, popular in industry and used in this course.
Step 3: write and run your first file
- Make a folder for your work, for example
python-coursein your Documents. - In VS Code: File → Open Folder… and choose it.
- File → New File…, name it
hello.py. The.pyending tells everyone it is a Python file. - Type this and save (Ctrl + S, or ⌘ + S on a Mac):
- Press the ▷ Run button at the top right. A terminal opens at the bottom and shows:
You can also run it yourself from the terminal. In VS Code open one with Terminal → New Terminal; it starts in your folder. Then:
VS Code shows "Select Interpreter"?
Press it (or press Ctrl + Shift + P and type Python: Select Interpreter) and choose the Python you installed. VS Code needs to know which Python to use.
The terminal in six commands
The terminal (also called the command line, shell or console) is a window where you type commands instead of clicking. It looks old-fashioned but it is how professionals install packages, run programs and use git. You only need a few commands:
| Do this | Windows (PowerShell) | macOS / Linux |
|---|---|---|
| Where am I? | pwd | pwd |
| What is in this folder? | ls (or dir) | ls |
| Go into a folder | cd python-course | cd python-course |
| Go up one folder | cd .. | cd .. |
| Make a folder | mkdir project1 | mkdir project1 |
| Run a Python file | py hello.py | python3 hello.py |
Two tricks save a lot of typing: press Tab to complete a file or folder name, and press ↑ to bring back the previous command.
The Python shell: try one line at a time
Type py (Windows) or python3 (macOS, Linux) on its own and you get the interactive shell, also called the REPL. The >>> prompt means "Python is waiting for a line". It runs each line as soon as you press Enter and shows the result, which is handy for quick experiments:
Type exit() to leave. Do not try to run a file from inside the shell: python hello.py typed after >>> gives a SyntaxError, because that is a terminal command, not Python.
Step 4: packages, pip and virtual environments
A package (or library) is code someone else wrote that you can reuse: pandas for tables, Matplotlib for charts, scikit-learn for machine learning. You install packages with pip, Python's package installer, which downloads them from the Python Package Index (PyPI).
Always install packages inside a virtual environment: a private folder of packages for one project. Why? Project A may need an old version of a package and project B a new one; with one environment per project they never clash, and you can delete an environment and rebuild it without breaking anything else. Professionals do this for every project.
In your project folder, in the terminal:
If PowerShell says running scripts is disabled, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, then activate again.
Inside an active environment, python and pip always mean "this project's Python", on every system. VS Code usually notices .venv and offers to use it; say yes (or pick it with Python: Select Interpreter).
To let someone else (or future you) rebuild the same environment, save the list of packages and reinstall from it:
Writing python -m pip instead of just pip guarantees pip installs into the same Python you run, which avoids the most common "I installed it but Python can't find it" problem.
Step 5: Jupyter notebooks
A notebook (.ipynb file) mixes code, results, charts and notes in cells you run one at a time. Data scientists use notebooks to explore data, and scripts (.py files) for finished programs. Two easy ways to get them:
- In VS Code: with your environment active, run
python -m pip install ipykernel. Then create a file ending in.ipynb; VS Code opens it as a notebook. Choose your.venvas the kernel (top right). - In the browser: run
python -m pip install notebook, thenjupyter notebook. It opens a page in your browser. - No install at all: Google Colab ↗. The playground on this site can also export your code as a notebook (More → Export as Jupyter notebook) to open in Colab.
In a notebook, press Shift + Enter to run a cell. Cells can run in any order, which is convenient but can confuse you: if results look strange, use Restart and Run All.
Fixing the usual problems
| You see | What it means | Fix |
|---|---|---|
'python' is not recognized… (Windows) | The terminal cannot find Python. | Use py instead. If that fails too, install the Python install manager, then close and reopen the terminal. |
Typing python opens the Microsoft Store | Windows' placeholder "app alias" answered instead of Python. | Use py, or turn off the python.exe aliases in Settings → Apps → Advanced app settings → App execution aliases. |
command not found: python (Mac, Linux) | The command is called python3 there. | Type python3 and pip3 (or activate a virtual environment). |
ModuleNotFoundError: No module named 'pandas' even though you installed it | You installed it into a different Python than the one running your code. | Activate the project's environment, run python -m pip install pandas, and select that environment in VS Code. |
error: externally-managed-environment | Your system does not let pip change its own Python. | Create and activate a virtual environment first (Step 4). |
SyntaxError after typing python hello.py | You typed it inside the Python shell (>>>). | Type exit() first, then run the command in the terminal. |
can't open file 'hello.py': No such file or directory | The terminal is in a different folder. | Use cd to go to the folder with the file (ls should list it), or open the folder in VS Code. |
Summary
Your checklist: Python installed (py --version or python3 --version works), VS Code with the Python extension, a project folder with a .venv virtual environment, and hello.py running. That is a professional setup, the same one used at work.
Key words
- interpreter
- the program that reads and runs Python code
- editor
- a program for writing code (VS Code)
- terminal
- a window where you type commands
- script
- a
.pyfile you run from start to end - REPL / shell
- the
>>>prompt that runs one line at a time - package
- reusable code written by others, installed with pip
- pip
- the tool that installs packages
- virtual environment
- a private set of packages for one project (
.venv) - notebook
- a file of code cells, outputs and notes (
.ipynb)
Common mistakes
- Installing packages without a virtual environment, then mixing up versions between projects.
- Typing
pip installand getting a different Python than the one running your code: usepython -m pip install. - Running terminal commands inside the
>>>shell, or Python code in the terminal. - Saving a file as
hello.py.txt: make sure the name really ends in.py. - Naming your own file after a package, such as
pandas.pyorrandom.py. Python then imports your file instead of the real package.
Quiz
1. On Windows, which command starts Python in the terminal with the current official installer?
2. On a Mac, which command reliably runs the Python you installed?
3. Why use a virtual environment for each project?
4. You installed pandas but get ModuleNotFoundError. What is the most likely cause?
5. What does python -m pip freeze > requirements.txt do?