Previous | Tutorial index | Next
To be able to install Python and required Python IDEs on the computer. Get Python and Python IDEs running for the learning activities included in this course.
Before you can write your first line of Python code, you need to set up your programming environment. This is the first practical hurdle every developer faces. Unlike many tutorials that gloss over installation issues, this guide provides detailed, step-by-step instructions for Windows, macOS, and Linux. More importantly, you will learn why certain steps (like adding Python to the PATH) are critical, and you will set up an Integrated Development Environment (IDE) that will make your coding journey smoother. By the end of this tutorial, you will be ready to write and run Python scripts on your own machine.
Python is cross-platform, but the installation process differs across operating systems. Follow the guide for your specific OS.
Download the Installer:
Run the Installer:
.exe file and double-click it.UAC Prompt:
Verification:
Win + R, type cmd, and hit Enter).python --version and press Enter.Python 3.12.x (or similar). If you see an error, you likely forgot the PATH step (see Section 9.7 Troubleshooting).macOS usually comes with an older version of Python 2.7 pre-installed for system use. Do not uninstall that version, as it is required by macOS itself. We will install a modern Python 3 separately.
Option A: Official Installer (Easiest)
.pkg file and follow the on-screen instructions.python3 command in your terminal.Option B: Homebrew (For developers)
If you have Homebrew installed, open the Terminal (Applications > Utilities > Terminal) and run:
brew install python
Homebrew automatically installs the latest Python 3 and pip.
Verification:
Open Terminal and type:
python3 --version
The system Python 2 is invoked by python (not python3). Always use python3 and pip3 on macOS.
Most modern Linux distributions (Ubuntu, Debian, Fedora) come with Python 3 pre-installed. However, you may need to install the full toolchain including pip and venv.
Ubuntu/Debian (APT):
sudo apt update
sudo apt install python3 python3-pip python3-venv
Fedora/RHEL (DNF):
sudo dnf install python3 python3-pip
Arch (Pacman):
sudo pacman -S python python-pip
Verification:
python3 --version. On Linux, like macOS, you must use python3 to invoke Python 3.When you type python in the command prompt/terminal, the operating system needs to know where the python.exe (or python3) file is located. It searches through all the directories listed in the PATH environment variable.
'python' is not recognized as an internal or external command error.C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python312\ and C:\Users\<YourUsername>\AppData\Local\Programs\Python\Python312\Scripts\ to the system PATH through System Properties > Environment Variables./bin directory to your .bashrc or .zshrc.A text editor lets you write code; an IDE (Integrated Development Environment) helps you write, debug, run, and manage it. IDEs provide features like syntax highlighting, auto-completion, debugging tools, and integrated terminals. We will set up three options, but VS Code is highly recommended for this course.
Ctrl+Shift+X / Cmd+Shift+X).Python (published by Microsoft).Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command Palette.Python: Select Interpreter.File > New File).hello.py.print("Hello, World!").Ctrl+F5 (Windows/Linux) / Cmd+F5 (Mac) to run the script. The output will appear in the integrated terminal at the bottom.New > Python File, name it hello.Thonny is incredibly simple and comes bundled with Python, making it the easiest to start with.
Regardless of the IDE you choose, you will need to use the terminal/command prompt occasionally.
View > Terminal or Ctrl+`. It defaults to your system shell.cd <folder> – Change directory.dir (Windows) / ls (macOS/Linux) – List files.python hello.py – Run a Python script.pip stands for "Pip Installs Packages." It is the package installer for Python. You use it to install third-party libraries from PyPI.
Check if pip is installed: pip --version (Windows) or pip3 --version (macOS/Linux).
Install a package:
pip install <package-name>
Example: pip install requests (to handle HTTP requests).
If you install all packages globally (pip install numpy), you will eventually run into issues: Project A needs numpy version 1.2, but Project B needs version 1.3. They conflict.
venv)A virtual environment is an isolated Python environment for a specific project. It has its own Python interpreter and its own pip directory.
How to create a virtual environment:
Open the terminal in your project folder.
Run:
python -m venv myenv
(Replace myenv with your desired environment name, e.g., venv).
Activate the environment:
myenv\Scripts\activatesource myenv/bin/activateOnce activated, your terminal prompt will show (myenv). Now, if you run pip install numpy, it installs only into this project folder.
Deactivate: deactivate
requirements.txtTo share your project, or to move it to another computer, you need to list all dependencies.
pip freeze > requirements.txtpip install -r requirements.txt| Issue | Likely Cause | Solution |
|---|---|---|
'python' is not recognized (Windows) |
Did not add Python to PATH. | Reinstall and check the PATH box, or manually add the install folder to PATH. |
python3: command not found (macOS/Linux) |
Python 3 is not installed. | Install it via the official installer or Homebrew/APT. |
pip: command not found |
Pip did not install with Python. | Use python -m pip install <package> instead of pip install, or install python3-pip (Linux). |
pip install gives Permission denied (macOS/Linux) |
Trying to install globally without sudo. |
Use --user flag: pip install --user <package>, or better, create a virtual environment. |
| VS Code cannot find the interpreter. | The Python extension is not installed, or the interpreter path is not detected. | Ctrl+Shift+P > Python: Select Interpreter > Choose your Python 3. |
py command works but python doesn't (Windows) |
The Python launcher (py) is installed. |
You can use py to run Python, but still add python to PATH for convenience. |
1. What is the most critical step when installing Python on Windows that beginners often forget?
2. On macOS and Linux, which command should you typically use to check if Python 3 is installed?
python -vpython3 --versionpython.exe --helppy --version3. The PATH environment variable tells the operating system:
4. Which of the following is NOT an IDE but rather a code editor that requires extensions to support Python?
5. In VS Code, how do you select the Python interpreter for your current project?
.interpreterCtrl+Shift+P) and selecting "Python: Select Interpreter"6. What makes Thonny a good choice for absolute beginners?
7. The standard package manager for Python is called:
8. What is the primary purpose of a virtual environment (venv)?
9. Which command activates a virtual environment named my_venv on Windows?
source my_venv/bin/activatemy_venv\Scripts\activateactivate my_venvvenv start my_venv10. To generate a list of all installed packages in a project to share with others, you use:
pip list > packages.txtpip freeze > requirements.txtpip export requirements.txtpython -m packages --list11. If pip is not found on your system, you can still install a package by using:
python pip install packagepython -m pip install packageinstall packagepip install --fixInstructions: Perform the following actions on your computer and tick them off. Write down the output for steps that ask for specific information.
Instructions:
Open your chosen IDE (we recommend VS Code).
Create a new folder named unit1-projects on your desktop.
Open that folder in VS Code (File > Open Folder).
Create a new file named hello.py.
Write the following code:
print("Hello, World!")
Run the script using the green play button or terminal command.
Modify the script to print your name. Example: print("My name is [Your Name]"). Run it again.
Submit: Note down any error messages you encountered (if any) and how you resolved them.
Instructions:
Open a terminal in your unit1-projects folder.
Create a virtual environment named venv:
python -m venv venv
(Note: On Windows, if python doesn't work, use py).
Activate the virtual environment:
venv\Scripts\activatesource venv/bin/activateVerify the prompt changed to (venv).
Install a popular package called requests:
pip install requests
Run pip freeze. You should see requests and its dependencies listed.
Export the list to requirements.txt:
pip freeze > requirements.txt
Open requirements.txt and confirm the entries are there.
Submit: Copy the output of pip freeze (after installing requests) and paste it into your exercise submission.
Instructions: A friend is trying to run hello.py and gets an error. Read the scenario below and write a one-sentence solution for them.
Scenario A: Alice types python hello.py in her Windows CMD and gets 'python' is not recognized....
Scenario B: Bob types pip install numpy in his Linux terminal and gets Permission denied.
Scenario C: Charlie writes print("Hello) (missing a closing quote) in VS Code. He runs it and gets an error. What kind of error is this?
Answer the following questions in complete sentences. Each response should be 3–5 sentences unless otherwise specified.
1. Explain the purpose of the "Add Python to PATH" option during Windows installation. What happens if you do not select it?
2. Why is it recommended to use a virtual environment (venv) for each Python project rather than installing all packages globally?
3. What is the difference between a command-line terminal and a Python IDE like PyCharm? Why might you need both?
Answer the following questions in 300–400 words each.
4. Imagine you are helping a friend who is completely new to programming install Python on their Windows computer. Write a step-by-step guide that explains not only what to click but why each step is important. Ensure you include how to write their first "Hello, World!" program.
Suggested outline:
--version does).hello.py (explain why creating a .py file matters).5. Describe your experience setting up the Python environment for this course. Which IDE did you choose? What specific challenges did you encounter during installation (e.g., PATH issues, permission errors, choosing the right interpreter), and how did you resolve them? If you had no challenges, explain what you did to ensure a smooth setup and what you would tell a classmate who is struggling.
Suggested outline:
These questions require additional research beyond the tutorial content.
6. Research the concept of "Linting" (e.g., using pylint or flake8 in VS Code). Why is it beneficial to have a linter installed in your IDE? How does it relate to PEP 8 (Python's style guide)?
7. Research the difference between the py launcher (Windows) and the python command. What is the purpose of the py launcher, and how does it simplify managing multiple Python versions on a single machine?
8. Research Jupyter Notebooks (.ipynb). How does a Jupyter Notebook differ from a traditional .py script and IDE? Why might a data scientist prefer a Jupyter Notebook for exploratory analysis? (Hint: Look at interactive cells, markdown support, and visualization integration).