Python is a versatile and beginner-friendly programming language used in web development, data science, automation, and more. A properly setup development environment is essential for writing, testing, and running your Python code efficiently.
This guide walks you through:
- Installing Python
- Setting up Visual Studio Code
- Creating a virtual environment
- Running your first Python script
What You’ll Need
- Computer: Windows, macOS, or Linux
- Internet Connection: To download tools and libraries
- Text Editor: Visual Studio Code (VS Code) recommended
- Time: 15–30 minutes for initial setup
Step 1: Install Python
1.1 Download Python
- Visit python.org/downloads
- Choose the latest version (Python 3.12 or higher)
1.2 Install Python
- Windows:
- Run the installer
- ✅ Check “Add Python to PATH”
- Click “Install Now”
- macOS:
- Run the
.pkg
installer and follow the prompts
- Run the
- Linux (Ubuntu example): bashCopy code
sudo apt update sudo apt install python3 python3-pip
1.3 Verify Installation
Open Terminal or Command Prompt and run:
bashCopy codepython3 --version
Expected output:
nginxCopy codePython 3.12.1
Step 2: Set Up Visual Studio Code (VS Code)
2.1 Install VS Code
- Download from code.visualstudio.com
- Follow the installer instructions for your OS
2.2 Install Python Extension
- Launch VS Code
- Go to Extensions panel (Ctrl+Shift+X or Cmd+Shift+X)
- Search Python and install the one by Microsoft
2.3 Configure VS Code
- Open a project folder:
File > Open Folder
- Set Python interpreter: arduinoCopy code
Ctrl+Shift+P > "Python: Select Interpreter"
Step 3: Create a Virtual Environment
Virtual environments isolate project dependencies to avoid conflicts.
3.1 Create Environment
In your terminal:
bashCopy codepython3 -m venv myenv
3.2 Activate Environment
- Windows: bashCopy code
myenv\Scripts\activate
- macOS/Linux: bashCopy code
source myenv/bin/activate
✅ When activated, you’ll see
(myenv)
in your terminal.
3.3 Deactivate
bashCopy codedeactivate
Step 4: Install a Package (e.g., requests
)
With the virtual environment active, install requests
:
bashCopy codepip install requests
Verify with:
bashCopy codepip list
Step 5: Write & Run Your First Python Script
5.1 Create hello.py
In VS Code, create a new file hello.py
and add:
pythonCopy codeimport requests
print("Hello, Python!")
response = requests.get("https://api.github.com")
print(f"GitHub API Status: {response.status_code}")
5.2 Run the Script
- Click the Run button in the top-right
- Or run in terminal:
bashCopy codepython3 hello.py
Expected output:
yamlCopy codeHello, Python!
GitHub API Status: 200
Step 6: Troubleshooting Tips
Problem | Solution |
---|---|
Python not found | Ensure it’s installed and added to PATH |
ModuleNotFoundError | Activate the virtual environment and check with pip list |
Code not running | Confirm interpreter selection and check for typos |
Tips for Long-Term Success
- Keep Python Updated – Check python.org regularly
- Use a virtual environment for every project
- Explore libraries – Try
pandas
,flask
,matplotlib
, etc. - Learn debugging – Use VS Code’s built-in debugger (F5)
Conclusion
You’ve successfully:
- Installed Python
- Set up VS Code
- Created a virtual environment
- Installed a package
- Run your first Python script
Now you’re ready to start exploring real-world Python projects like:
- Web apps with Flask or Django
- Data visualization with Matplotlib
- Automation with scripts
Next Step: Try building a to-do list app or automating a task you do daily!