4.2 KiB
Step-by-Step Complete Setup Guide
Prerequisites
Before starting, ensure you have Python 3.x installed on your system.
Check Your Python Installation
Open PowerShell or Terminal:
Press Windows + R, type powershell, press Enter (on Windows)
Check Python Version:
python --version
# Should show: Python 3.x.x
# If that doesn't work, try:
python3 --version
# Or on some systems:
py --version
Create Your Project Folder
Organize your files properly from the start.
Open PowerShell, Terminal, or Command Prompt:
Make sure you're not in the Python shell (should see C:> or PS C:>).
Navigate to Desktop or Documents:
Let's create a folder on your Desktop for easy access:
# Go to Desktop (Windows)
cd Desktop
# Create a new folder for your project
mkdir project_folder
# Go into your new folder
cd project_folder
# Verify you're in the right place
pwd
# Should show: C:\Users\YourName\Desktop\project_folder
# Or use 'ls' to see files (should be empty)
ls
Best Practice: Keep all related files in one folder for easy management.
Set Up Virtual Environment (venv)
Isolate project dependencies for clean development.
Why Virtual Environment?
- Keeps project dependencies separate
- Avoids version conflicts between projects
- Makes sharing and deployment easier
Create Virtual Environment:
Make sure you're in your project_folder, then run:
# Create virtual environment named 'venv'
python -m venv venv
# or
python3 -m venv venv
# Check if venv folder was created
ls
# You should see a 'venv' folder in the list
Activate Virtual Environment:
On Windows (PowerShell):
venv\Scripts\Activate.ps1
# If you get an error about execution policy, run this first:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
venv\Scripts\Activate.ps1
On Windows (Command Prompt):
venv\Scripts\activate
On Mac/Linux:
source venv/bin/activate
Success Indicator: You should see (venv) at the start of your command line.
Install Required Libraries
Get the Python packages needed for this project.
First, activate your venv:
Make sure you see (venv) before the prompt.
Install required packages:
# Install the required library
pip install package-name==version.number
# Verify installation
pip show package-name
# Should show the installed version
Create Requirements File:
pip freeze > requirements.txt
# View the requirements file
type requirements.txt
# (Mac/Linux: use 'cat requirements.txt' instead of 'type')
Why this matters: Anyone can install exact same versions with pip install -r requirements.txt
Using IDLE Editor
To open Python IDLE editor:
On Windows:
# Launch IDLE (blank new file)
py -m idlelib.idle
# OR (depending on your Python installation)
python -m idlelib.idle
# Open an existing file
py -m idlelib.idle "C:\path\to\your\file.py"
On Mac:
# Launch IDLE (blank new file)
python3 -m idlelib.idle
# OR (if installed)
idle3
# Open an existing file
python3 -m idlelib.idle ~/path/to/your/file.py
On Linux:
# Launch IDLE (blank new file)
python3 -m idlelib.idle
# OR (if installed)
idle3
# Open an existing file
python3 -m idlelib.idle /path/to/your/file.py
Copy Existing Code
Start with our working code and modify it.
Create main file:
In your project_folder, create a new file:
# Using Python IDLE or any text editor:
notepad app.py
# (Or use VS Code, Sublime Text, or Python's IDLE)
Expected Folder Structure:
project_folder/
├── app.py # Main file
├── requirements.txt # Python dependencies
└── venv/ # Virtual environment
Final Steps
Once you have completed all the steps above, you'll have a properly configured Python development environment ready for your project. Remember to always activate your virtual environment (source venv/bin/activate on Mac/Linux or venv\Scripts\Activate.ps1 on Windows) before starting work on your project.