Welcome to your Python programming journey! This comprehensive guide will get you set up with a Python environment ready for coding. We’ll cover installing Python and setting up virtual environments – a crucial best practice for managing projects.
Table of Contents
Python 3 Installation
Download the latest stable Python 3 release from the official website: https://www.python.org/downloads/
Windows:
- Download the Windows installer (
.exe
). - Run the installer. Ensure you check “Add Python to PATH” to easily run Python from your command prompt.
- Follow the on-screen instructions.
- Verification: Open your command prompt (search for “cmd”) and type
python --version
. You should see the installed version.
macOS:
- Download the macOS installer (
.pkg
). - Run the installer and follow the instructions.
- Verification: Open your terminal (Applications > Utilities > Terminal) and type
python3 --version
(orpython --version
ifpython3
doesn’t work).
Linux:
Installation varies by distribution. Use your distribution’s package manager:
- Ubuntu/Debian:
sudo apt update && sudo apt install python3
- Fedora:
sudo dnf install python3
Consult your distribution’s documentation for specific instructions. Verify with python3 --version
(or python --version
).
Virtual Environment Setup
Virtual environments isolate project dependencies, preventing conflicts. They’re created using the venv
module (built into Python 3).
1. Creating a Virtual Environment:
Open your terminal, navigate to your project directory, and run:
python3 -m venv <your_env_name>
(Replace <your_env_name>
with your environment’s name, e.g., myproject
).
2. Activating a Virtual Environment:
- Windows:
<your_env_name>Scriptsactivate
- macOS/Linux:
source <your_env_name>/bin/activate
You’ll see the environment name (e.g., (myproject)
) in your terminal prompt.
3. Deactivating a Virtual Environment:
Type deactivate
in your terminal.
Congratulations! You’re ready to start coding in Python. Happy programming!