Python Setup
Install Python, set up your development environment, and run your first Python program.
This guide helps you install Python, run a first program, create a virtual environment, and install packages.
You can write Python in VS Code, Notepad, or any other text editor. The editor does not run Python. The terminal runs Python.
Windows
1. Install Python from the Microsoft Store (recommended)
For most beginners, the Microsoft Store is the simplest way to install Python:
- Open the Microsoft Store.
- Search for Python 3.
- Choose a current Python 3 release from the Python Software Foundation.
- Select Get or Install.
Close and reopen any terminal that was already open after installation.
2. Install Python from python.org (fallback)
If the Microsoft Store method is unavailable or causes problems, download Python 3 from:
https://www.python.org/downloads/
Open the installer. On the first screen, tick:
Add python.exe to PATH
Then select Install Now.
3. Check Python
Close any terminal that was already open. Open a new PowerShell or Command Prompt window and run:
python --version
You should see something similar to:
Python 3.13.7
Also check pip:
python -m pip --version
If both commands work, Python is ready and you can continue to run your first program.
If you see a message like:
'python' is not recognized as the name of a command
then Python is either not installed correctly or was not added to PATH. Try these steps in order:
- Close and reopen the terminal.
- If you installed Python from the Microsoft Store and
pythonstill does not work, check that the Store installation completed and reopen the terminal. - If you installed Python from python.org, run the installer again and make sure Add python.exe to PATH is enabled.
- If necessary, add the python.org installation to PATH using the steps below.
4. Turn Off the Microsoft Store Alias
Sometimes Windows opens the Microsoft Store when you type python instead of running an installed Python version. This happens because Windows has a placeholder alias named python.exe.
Turn it off:
- Open Windows Settings.
- Open Apps.
- Select Advanced app settings.
- Select App execution aliases.
- Turn off
python.exeandpython3.exeif they point to the Microsoft Store. - Close and reopen the terminal.
- Run
python --versionagain.
Searching Windows Settings for App execution aliases is usually the quickest way to find this page.
5. Add Python to PATH Manually
Use this only if running the python.org installer again with Add python.exe to PATH does not fix the problem. If you installed Python from the Microsoft Store and python --version works, Python is already available and you do not need this section.
Find the installation without using a Python command: open the Start menu, search for Python, right-click the Python result, and choose Open file location. If this opens a shortcut, right-click the shortcut and choose Open file location again. The folder containing python.exe is the folder you need.
For a python.org installation, its Scripts folder is usually next to the folder containing python.exe. Add both folders to PATH. If you cannot find Python, run the python.org installer again and select Add python.exe to PATH.
To edit PATH:
- Search Windows for
environment variables. - Open Edit the system environment variables.
- Select Environment Variables.
- Under User variables, select
Pathand choose Edit. - Add both folders with New.
- Confirm all dialogs.
- Open a new terminal and run
python --versionagain.
6. Allow Virtual-Environment Activation in PowerShell
When you later activate a virtual environment, PowerShell may say that running scripts is disabled.
For the current Windows user, run PowerShell normally and enter:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Confirm the prompt. This does not require administrator access.
Unrestricted allows more scripts to run. Use this command only on a computer where you understand the setting. Do not run unknown scripts.
7. Run a First Program
Open Notepad and save this as hello.py:
print("Hello from OSDC")
When saving in Notepad:
- Set Save as type to All files.
- Save the file as
hello.py, nothello.py.txt.
Open a terminal in the folder containing the file. In File Explorer, open the folder, click the address bar, type powershell, and press Enter.
Run the program:
python hello.py
macOS
1. Install Python
Download Python 3 from:
https://www.python.org/downloads/macos/
Open the installer and follow the steps. It provides the python3 command.
If Homebrew is already installed, you can use:
brew install python
2. Check Python
Open the Terminal application and run:
python3 --version
python3 -m pip --version
You should see a Python 3 version. On macOS, use python3 rather than python because python may not exist or may refer to another system tool.
If python3 is not found, reopen Terminal. If it still does not work, reinstall Python from the official installer or check your shell PATH.
3. Run a First Program
Create a file named hello.py in any editor:
print("Hello from OSDC")
Open Terminal in that file’s folder and run:
python3 hello.py
Linux
1. Install Python
Most Linux distros (distributions) already come with Python installed by default. First check whether Python 3 is available:
python3 --version
If that command works, you may only need to install the package tools required for this workshop. If it does not work, install Python using your distribution’s package manager below.
Use the package manager for your Linux distribution.
Ubuntu or Debian:
sudo apt update
sudo apt install python3 python3-pip python3-venv
Fedora:
sudo dnf install python3 python3-pip
Arch Linux:
sudo pacman -S python python-pip
2. Check Python
On Ubuntu, Debian, and Fedora, run:
python3 --version
python3 -m pip --version
On Arch Linux, either python or python3 may be available:
python --version
python -m pip --version
Linux package installations normally add Python to PATH automatically. If the command is not found, use your distro’s package manager documentation and open a new terminal after installation.
3. Run a First Program
Create a file named hello.py in any editor:
print("Hello from OSDC")
Open a terminal in that file’s folder and run:
python3 hello.py
Using Any Editor
VS Code, Notepad, Notepad++, nvim, vim, nano, emacs and other editors can be used to write Python files.
Code::Blocks is not recommended for Python because it is primarily designed for C and C++, but it can still be used as an editor.
The basic workflow is always:
- Create a plain-text file ending in
.py. - Write Python code.
- Save the file.
- Open a terminal in the file’s folder.
- Run the file with Python.
VS Code
-
Install VS Code from:
https://code.visualstudio.com/ -
Install the official Python extension by Microsoft.
-
Open your project folder.
-
Open a
.pyfile. -
Select the Python interpreter if VS Code asks.
-
Open the integrated terminal with Terminal > New Terminal.
-
Run the file from the terminal:
python filename.py
On macOS and Linux, use python3 filename.py before activating a virtual environment.
VS Code also provides a Run Python File button in the top-right of a Python file. It uses the interpreter selected in VS Code.
Notepad
Notepad is enough for the first Python programs. Save the file with the .py extension and make sure it does not become .py.txt.
Virtual Environments
A virtual environment is a separate Python setup for one project. Packages installed inside it stay separate from other projects.
Create the environment inside your project folder.
Windows PowerShell
python -m venv .venv
.venv\Scripts\Activate.ps1
Windows Command Prompt
python -m venv .venv
.venv\Scripts\activate.bat
macOS and Linux
python3 -m venv .venv
source .venv/bin/activate
After activation, the terminal usually begins with (.venv). Check that the environment is active:
python --version
python -m pip --version
On Windows, use the same commands after activation.
Installing Packages
Activate the virtual environment first, then install the package with Python’s pip module.
python -m pip install requests
For the FastAPI workshop:
python -m pip install "fastapi[standard]"
Install packages listed in an existing project file:
python -m pip install -r requirements.txt
Using python -m pip makes sure the package is installed for the Python interpreter currently being used.
Deactivating the Environment
When you are finished working, run:
deactivate
You can activate the same .venv again the next time you work on the project.
Troubleshooting
python Is Not Recognized on Windows
If you installed Python from python.org, you can optionally check whether its launcher is available:
py --version
The py command may not exist, especially when Python was installed from the Microsoft Store. If py is also not recognized, reinstall Python from python.org with Add python.exe to PATH enabled. You can then run programs with python filename.py.
Python Opens the Microsoft Store
Turn off the python.exe and python3.exe entries in Windows App execution aliases, then reopen the terminal.
PowerShell Does Not Allow Activation
Run this command as your normal user:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Then try activation again.
The File Is Called .py.txt
Enable File name extensions in File Explorer and rename the file so it ends exactly in .py.
A Package Cannot Be Imported
Make sure the virtual environment is active, then install the package again:
python -m pip install package-name
