Curriculum
Before you can start coding in Python, you need to install it on your computer. In this section, we will cover:
By the end of this section, you should have Python fully installed and ready to use.
As you work through the following steps, feel free to navigate to this GeeksForGeeks link for more assistance.
Before installing Python, you could check if it is already installed on your computer. At times, this could be the case, especially with macs. Based on your operating system, follow the appropriate instruction below:
python --version
or
python3 --version
python3 --version
If Python is installed, you will see an output like:
Python 3.10.5
If Python is already installed, you can skip to 1.3.4 Running Python.
If Python is not installed, follow the steps below to install it.
python-3.x.x.exe
) and double-click it to start the installation.After installation, open Command Prompt (cmd) and type:
python --version
You should see something like:
Python 3.10.5
Most macOS versions come with Python pre-installed. Check by running:
python3 --version
If it shows a version lower than Python 3.7, you should install the latest version.
Homebrew is a package manager for macOS that makes installation easier.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install Python using Homebrew:
brew install python
3. Verify the installation:
python3 --version
You should see an output like:
Python 3.10.5
Most Linux distributions come with Python pre-installed. To check:
python3 --version
If Python is not installed or needs an update, use apt:
sudo apt update
sudo apt install python3
Use dnf:
sudo dnf install python3
Verify installation by running:
python3 --version
pip allows you to install external Python libraries.
Python 3.x comes with pip pre-installed, but you can manually install or upgrade it:
pip --version
python -m ensurepip --default-pip
pip install --upgrade pip
Now you can install packages like NumPy, pandas, Flask, etc.
Example: Installing NumPy
pip install numpy
Once Python is installed, you can run it in two ways:
Python provides an interactive shell (Read-Eval-Print Loop, REPL) where you can type commands and get instant results.
Open Command Prompt (Windows) or Terminal (macOS/Linux) and type:
python
or
python3
You will see the Python prompt (>>>
), indicating that Python is ready to execute commands.
Example: Running Python Commands in REPL
>>> print("Hello, Python!")
Hello, Python!
>>> 2 + 3
5
>>> exit() # Type 'exit()' to leave the Python shell
This is how you use Python interactively. But we shall not use this approach however.
Python scripts are files with the extension .py
. This indicates that the file contains Python code.
Example: Creating and Running a Python Script
Open a text editor (Notepad, VS Code, or PyCharm – Next Section).
Type the following code and save the file as hello.py
:
print("Welcome to Python Programming!")
Open Command Prompt/Terminal, navigate to the file’s location, and run:
python hello.py
Output:
Welcome to Python Programming!
Terrific! you have successfully written and executed your first Python script!
If you did not get this working, do not fret. When we get PyCharm working, it should be easier.
While Python can be run in the terminal, using an Integrated Development Environment (IDE) improves coding efficiency. While we shall cover how to install PyCharm in the next section, here are a few popular IDEs for developing code in Python.
Popular Python IDEs and Code Editors:
IDE/Editor | Features | Best For |
---|---|---|
PyCharm | Full-featured, debugging, autocomplete | Professionals |
VS Code | Lightweight, extensions, debugging | Beginners & Professionals |
Jupyter Notebook | Best for Data Science, inline graphs | Data Science, AI |
IDLE | Comes with Python, simple interface | Absolute Beginners |
Here is a summary of what we have discussed in this section.
brew install python
).sudo apt install python3
).python --version
.pip install --upgrade pip
.python
in the terminal..py
file and execute it.Now that you have installed Python, let’s move to Chapter 1.4: Setting Up PyCharm as Your IDE, where we will configure PyCharm for a professional coding experience.
Not a member yet? Register now
Are you a member? Login now