To write and run Python programs, you first need to install Python on your computer. The latest version of Python can be downloaded from the official website:
🔗 https://www.python.org/downloads/
Choose the version that matches your operating system:
.exe
installer..pkg
installer.When installing Python on Windows, make sure to check the option:
[✓] Add Python to PATH
This ensures you can run Python from any terminal or command prompt window.
After installation, open your terminal (or command prompt) and type:
python --version
Or, on some systems:
python3 --version
You should see something like:
Python 3.11.7
If you see an error or it says Python is not recognized, it means Python wasn't added to your system path properly.
There are multiple ways to run Python code:
Open your terminal and type:
python
This opens a live Python environment where you can type and run commands line-by-line.
example:
>>> print("hello")
hello
To exit, type exit()
or press Ctrl + Z
(Windows) or Ctrl + D
(macOS/Linux).
You can write code in a file with the .py
extension.
example (example.py
):
print("This is a file")
Run it using:
python example.py
You can write Python using any text editor, but using an IDE (Integrated Development Environment) makes development much easier.
Here are some popular options:
They offer:
example (VS Code):
# my_script.py
name = input("What is your name? ")
print("Welcome,", name)
Run your file directly inside the editor or using the terminal.
Python comes with a tool called pip
— it helps you install extra features and libraries written by other developers.
To check if pip
is installed:
pip --version
To install a package:
pip install package-name
example:
pip install requests
Then in Python:
import requests
You now have access to that package's features.
Sometimes you may want to isolate your project’s packages so that they don’t conflict with other projects. That’s where virtual environments come in.
To create one:
python -m venv myenv
To activate it:
bash
myenv\Scripts\activate
* macOS/Linux:
bash
source myenv/bin/activate
Now you can install packages without affecting the global environment.
To deactivate:
deactivate
--user
to your pip install command:bash
pip install package-name --user
* Using wrong version: Use python3
instead of python
if your system has Python 2 by default.
Setting up Python is the first step toward building anything with it. Once you’ve installed Python and chosen an editor, you're ready to write code and explore the full power of the language.
From here, we’ll dive into the syntax and structure of Python programs in the next section.