Step 1: Download Python
Visit the official Python website at python.org, and follow these steps to download Python:
- Click on the “Downloads” tab.
- Choose the version of Python you want to install. It’s recommended to use the latest stable version (e.g., Python 3.9).
- Click on the download link that corresponds to your operating system (Windows, macOS, or Linux).
Step 2: Run the Installer
For Windows:
- Open the downloaded executable file (
.exe
). - Check the box that says “Add Python to PATH” during installation.
- Click “Install Now” to start the installation.
For macOS:
- Open the downloaded package (
.pkg
) file. - Follow the installation prompts.
- Ensure that you check the box to add Python to your PATH.
For Linux:
- Open a terminal.
- Navigate to the directory containing the downloaded file.
- Run the following commands:
tar -xf Python-3.x.x.tgz
cd Python-3.x.x
./configure
make
sudo make install
Step 3: Verify Installation
To verify that Python has been installed correctly, open a terminal or command prompt and type the following command:
python --version # For Python 2
or
python3 --version # For Python 3
You should see the version number of the Python interpreter you just installed.
Step 4: Install a Code Editor (Optional)
While you can write Python code in any text editor, using a code editor with features like syntax highlighting and autocompletion can enhance your development experience. Some popular code editors for Python include:
Step 5: Set Up a Virtual Environment (Optional but Recommended)
Using virtual environments is a best practice for Python development to isolate project dependencies. To set up a virtual environment, follow these steps:
- Open a terminal or command prompt.
- Navigate to your project directory.
- Run the following commands:
python -m venv venv # For Python 3
or
virtualenv venv # For Python 2
- Activate the virtual environment:
- On Windows:
.\venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
Step 6: Start Coding!
You’ve successfully set up your Python development environment. Now you’re ready to start writing and running Python code.
print("Hello, Python!")
Save the file with a .py
extension and run it using the terminal or command prompt:
python your_file.py # For Python 2
or
python3 your_file.py # For Python 3
Congratulations! You’ve completed the initial setup for Python development. In the next sections, we’ll explore the basics of Python programming.