Python is a powerful, versatile programming language used in web development, data science, artificial intelligence, and more. This guide will walk you through installing Python and setting up three popular development environments: IDLE, VS Code, and PyCharm.
1. Installing Python
Before you start coding, ensure Python is installed on your system.
Windows
- Download Python:
- Visit python.org and download the latest version.
- Run the Installer:
- Check “Add Python to PATH” before installation.
- Click “Install Now” and follow the prompts.
- Verify Installation:
Open Command Prompt and run:python --version
You should see something likePython 3.x.x
.
macOS
- Install via Homebrew (recommended):
brew install python
Alternatively, download it from python.org. - Verify Installation:
python3 --version
Linux
- Install via Terminal:
sudo apt update && sudo apt install python3
- Verify Installation:
python3 --version
2. Setting Up Your Development Environment
IDLE (Integrated Development and Learning Environment)
IDLE is Python’s built-in editor, ideal for beginners.
- Open IDLE:
- Windows: Search for IDLE in the Start menu.
- macOS/Linux: Run
idle3
in the terminal.
- Write and Run Code:
- Go to File > New File, write your Python code, and save it as
.py
. - Run it using Run > Run Module.
- Go to File > New File, write your Python code, and save it as
VS Code (Visual Studio Code)
A lightweight, feature-rich editor for Python development.
- Download and Install VS Code:
- Get it from code.visualstudio.com.
- Install Python Extension:
- Open VS Code, go to the Extensions tab, and search for Python (by Microsoft). Install it.
- Select Python Interpreter:
- Press
Ctrl+Shift+P
(Windows/Linux) orCmd+Shift+P
(macOS). - Type “Python: Select Interpreter” and pick the installed version.
- Press
- Run Your Code:
- Write Python code in a
.py
file and run it using the Run Python File button or terminal.
- Write Python code in a
PyCharm
A powerful, professional IDE for Python development.
- Download PyCharm:
- Get the Community Edition (free) from jetbrains.com/pycharm.
- Install and Set Up:
- Follow the installation prompts for your OS.
- Create a New Project:
- Open PyCharm, click “New Project”, and select your Python interpreter.
- Run Your Code:
- Write a
.py
file, then click the Run button (green play icon).
- Write a
3. Setting Up a Virtual Environment (Recommended)
Using virtual environments keeps project dependencies separate.
Using venv
(Built-in Virtual Environment Manager)
- Create a Virtual Environment:
python3 -m venv myenv # Replace "myenv" with your environment name
- Activate the Virtual Environment:
- Windows:
myenv\Scripts\activate
- macOS/Linux:
source myenv/bin/activate
- Windows:
- Deactivate It:
deactivate
Virtual Environments in IDEs
- VS Code: Select the virtual environment interpreter in the Python extension settings.
- PyCharm: Choose the virtual environment when creating a new project.
4. Testing Your Setup
Create a simple Python script to verify everything works:
# hello.py
print("Hello, World!")
print(3 + 5) # Outputs: 8
Run it in IDLE, VS Code, PyCharm, or your terminal to confirm your setup.
5. Choosing the Right Development Environment
- IDLE: Best for beginners and quick scripts.
- VS Code: Lightweight and extensible for most projects.
- PyCharm: Full-featured IDE for professional development.
Choose what works best for you and start coding!