Python is a powerful general-purpose programming language. It is used in:
- Machine Learning
- Web Development
- Data Analysis
- Scientific Research
- Automation
Python has a simple and easy-to-use syntax compared to other programming languages. That's why Python is an excellent language for beginners.
Running Python
The simplest way of running Python code is by using an online Python editor like Python Interpreter.
You can also easily install and run Python code locally on your computer.
Install and Run Python on Windows
You can install Python on Windows in the following steps.
- Install Python
- Verify Python Installation
- Verify pip Installation
- Run Python Code
Now, let's explore the process further.
Step 1. Install Python
First, go to Python's official website and download the version compatible with your device.
If you have 32-bit Operating System, select the 32-bit installer. If you have a 64-bit installer, you can select any version.
Now, download the selected version and run the Python installer. You will see the following screen.
Make sure you select "Add Python 3.10 to PATH" option in the setup wizard. Then, simply choose the Install Now option.
If you see the "Setup was successful" screen, Python is installed on your windows.
Step 2: Verify Python Is Installed
To verify the python installation:
- Go to the search menu and search for Command Prompt.
- Select Command Prompt and type
python
. - If your Python installation is successful, it will display the python the version you just installed.
Step 3: Verify pip Is Installed
The next step is to verify pip installation. pip
is the standard
package manager for Python. You can use pip to install additional packages
that are not available in the Python standard library.
You will start using pip every now and then once you start building Python projects. To learn more about pip, visit Python pip.
Usually, pip is installed along with Python. To ensure the installation,
- Go to the search menu and start Command Prompt.
- Open the command prompt and type pip -V.
- If pip is installed, it will display the pip version.
Step 4: Run Python Code
Now, you are ready to run Python code.
When you install Python, it also installs an IDE name IDLE.
Go to the Start button and search Python to find the Python shell.
You can write basic Python commands in this Python shell. Let's see an example by running a simple "Hello World" program.
However, to run large projects, you will need to install other IDEs, such as Pycharm, VS Code orThonny.
To learn more about Python IDEs, visit Python IDEs and Code Editors.
Install Python on macOS
Usually, macOS comes with Python 2.7 version installed with it. But since it is not a compatible version to use today, we need to upgrade Python.
Before upgrading Python, first, check the Python version by running the following command on the terminal.
python -version
If it displays the latest version, you do not need to upgrade Python.
However, if it shows Python 2.7, you will need to upgrade Python.
You can install/upgrade the latest Python version on your Mac in the following steps:
Step 1: Download Python installer
Visit Python's official website and download the version you want to install.
Once you download the Python installer, you usually have to keep pressing the continue button and agree to the terms and conditions.
Follow the instructions given by the setup wizard, and Python will be installed on your Mac.
Step 2: Verify Python Is Installed
To verify the python installation:
- Go to your Terminal and type
python -version
. - If it displays the version you just installed, your Python installation is verified.
Install Python on Linux
Most of the Linux distributions also already have Python installed. To verify if your Linux has Python, type
python -version
If it displays the Python with the version number, for example,
Python 3.10.5
Then, you already have Python on your Linux.
If not, you can install Python on Linux in the following steps:
Step 1: Install Python Using Terminal
Suppose you want to install Python 3.10.7. Open the terminal and type
sudo apt-get install python3.10.7
Once you run it, you will need to enter your sudo password. You also need to give it permission to use your hard disk space. For that, just type Y and enter.
Then, the installation process will begin, and if the installation ends with no error messages, your Python installation is completed.
Step 2: Verify Python Is Installed
To verify your Python installation,
- Open your terminal and type
python -version
. - If it displays the version you just installed, Python installation is verified.