Setting up Python and running your first program is quick and easy—get started in just 5 minutes!
Python is one of the most beginner-friendly programming languages, and that’s a big reason why it’s so popular. Whether you’re interested in web development, data science, automation, or AI, Python is a great place to start. It has a simple syntax, a massive community, and works on almost any operating system. In this guide, you’ll learn how to install Python and run your first Python script in just a few minutes. Let’s get started!
Before installing Python, let’s check if it’s already on your system. Open your terminal (Mac/Linux) or command prompt (Windows) and type:
python --version
or
python3 --version
If Python is installed, you’ll see an output like this:
Python 3.x.x
If you get an error or no version is displayed, that means Python isn’t installed, and you’ll need to install it manually. Let’s do that next!
To install Python, you’ll need to download the latest version from the official Python website:
Let’s go through the process step by step for Windows, macOS, and Linux.
Win + R, type cmd, and press Enter), then type: bashCopyEditpython --version
If Python is installed correctly, you’ll see an output like:
Python 3.x.x
Cmd + Space, type Terminal, and press Enter), then run:python3 --version
If Python is installed correctly, you should see:
Python 3.x.x
Most Linux distributions come with Python pre-installed. But if you need to install or update it, follow these steps:
python3 --version
If you see something like Python 3.x.x, you’re good to go! If not, install it using the following commands based on your Linux distribution:
2. Install Python on Ubuntu/Debian:
sudo apt update && sudo apt install python3
3. Install Python on Fedora:
sudo dnf install python3
4. Install Python on Arch Linux:
sudo pacman -S python
5. Verify Installation: After installation, run:
python3 --version
You should see:
Python 3.x.x
Now that Python is installed, let’s move on to running your first Python program!
Now that Python is installed, let’s write and run your first program! There are two main ways to run Python code:
The Python Interactive Shell (also called the REPL) lets you run Python commands one at a time. This is great for quick tests and debugging.
python
(If this doesn’t work, try python3 instead.)
3. You should see something like this:
Python 3.x.x (default, YYYY-MM-DD)
Type "help", "copyright", "credits" or "license" for more information.
>>>
4. Now, type this simple command and press Enter:
print("Hello, Python!")
5. You should see the output:
Hello, Python!
6. To exit the shell, type:
exit()
or press Ctrl + Z (Windows) / Ctrl + D (Mac/Linux).
If you want to save your code and run it later, you need to write a Python script (a .py file).
print("Welcome to Python programming!")
3. Save the File
4. Run the Script
cd:cd path/to/your/file
(For example, if your file is in Documents/Python, use cd Documents/Python.)
Run the script with:
python first_program.py
(If this doesn’t work, try python3 first_program.py.)
5. See the Output!
You should see:
Welcome to Python programming!
While you can write and run Python programs using a basic text editor and terminal, using an IDE (Integrated Development Environment) makes coding easier. An IDE provides syntax highlighting, auto-completion, debugging tools, and better organization.
Here are three great options for beginners:
idle in the command prompt (Windows) or terminal (Mac/Linux)..py file is saved..py file to open it in VS Code.Ctrl + Shift + P and type Run Python File in Terminal..py file.Shift + F10.Using an IDE makes writing, debugging, and running Python code much easier. If you’re serious about learning Python, setting up an IDE is a great step!
Sometimes, after installing Python, you might run into issues when trying to use it. Here’s how to fix some of the most common problems.
If you see an error like this when running python in the command prompt (Windows) or terminal (Mac/Linux):
'python' is not recognized as an internal or external command, operable program, or batch file.
or
command not found: python
it means Python isn’t added to your system’s PATH. Here’s how to fix it:
Win + R, type cmd, and press Enter).where python
Add Python to PATH (Windows 10/11)
Path, then click Edit.C:\Python39\ or C:\Users\YourUsername\AppData\Local\Programs\Python\Python39\).Check if Python Works
python --version
You should see something like:
Python 3.x.x
which python
If nothing appears, try:
which python3
2. Use python3 Instead
python3 --version
python still runs Python 2, you can set python to use Python 3:alias python=python3
On some older systems, running python might start Python 2, which is outdated.
python --version to check which version is running.python3 instead:python3 --version
If that works, you can update your system to use python instead of python3:
py -3
python3 instead of python.python to default to Python 3, set an alias:alias python=python3
echo "alias python=python3" >> ~/.bashrc
Then restart your terminal.
Once you’ve fixed the issues, run:
python --version
or
python3 --version
If you see Python 3.x.x, you’re good to go!
You’ve successfully installed Python and run your first script! 🎉 Let’s quickly recap what we covered:
This is just the beginning of your Python journey! Now that you have Python up and running, here are some great next steps:
➡ Learn Python basics: Explore concepts like variables, loops, functions, and lists.
➡ Write more Python scripts: Automate tasks, build small programs, and get hands-on practice.
➡ Explore Python frameworks: Start with Flask for web development, Pandas for data analysis, or TensorFlow for AI.
Ready to take the next step? Check out our guide on Python Basics for Beginners to continue your learning!
.py extension, then open the Command Prompt or Terminal, navigate to the file location, and run the script by typing “python” followed by the filename.After debugging production systems that process millions of records daily and optimizing research pipelines that…
The landscape of Business Intelligence (BI) is undergoing a fundamental transformation, moving beyond its historical…
The convergence of artificial intelligence and robotics marks a turning point in human history. Machines…
The journey from simple perceptrons to systems that generate images and write code took 70…
In 1973, the British government asked physicist James Lighthill to review progress in artificial intelligence…
Expert systems came before neural networks. They worked by storing knowledge from human experts as…
This website uses cookies.