Python Setup Guide
You’ll be working with preconfigured Codespaces and, later on, Jupyter Notebooks—no local installation is required. However, this guide is intended for anyone who wants to install Python locally, either for future coursework or for developing capstone projects.
This guide covers how to install Python using Anaconda, set up development environments on both Windows and macOS, handle common edge cases (like old Python 2.x installations), install essential packages, and configure PyCharm and VSCode with WSL.
Table of Contents
- Prerequisites
- Installation on Windows with WSL
- Installation on macOS
- Creating and Using Virtual Environments
- Troubleshooting Common Issues
- Testing Your Setup with a Python Script
- Installing PyCharm and Connecting to WSL
- Installing VSCode and Connecting to WSL
- Adding Python Interpreter in PyCharm and VSCode
- Installing Python Packages in WSL and Extensions for VSCode
Prerequisites
Before you start:
- Ensure you have at least 10 GB of free space on your device.
- Verify your device is 64-bit (most are).
- Check if you have any old installations of Python 2.x. If you do, follow the Troubleshooting section to avoid conflicts.
Installation on Windows with WSL
Step 1: Install Windows Subsystem for Linux (WSL)
- Open PowerShell as Administrator.
- Run the following command:
wsl --install - Restart your computer when prompted.
- Open Ubuntu from the Start menu and set up a username and password for WSL.
Step 2: Install Anaconda on WSL
- Download the Anaconda installer:
wget https://repo.anaconda.com/archive/Anaconda3-latest-Linux-x86_64.sh - Run the installer:
bash Anaconda3-latest-Linux-x86_64.sh - Follow the prompts and answer yes when asked to initialize Anaconda.
- Restart your WSL terminal or run:
source ~/.bashrc
Verify Anaconda installation:
conda --version
Installation on macOS
Step 1: Uninstall Old Python Versions (if necessary)
- Open Terminal.
- Check for old Python installations:
python --version
If Python 2.x is installed, ensure you follow the Troubleshooting section to avoid conflicts.
Step 2: Install Anaconda on macOS
- Download the Anaconda installer from the official website.
- Open Terminal and navigate to your Downloads folder:
cd ~/Downloads - Run the installer:
bash Anaconda3-latest-MacOSX-x86_64.sh - Close and reopen the Terminal, then verify the installation:
conda --version
Creating and Using Virtual Environments
What is a Virtual Environment?
A virtual environment isolates Python dependencies for different projects, avoiding conflicts.
Step 1: Create a Virtual Environment
- Open your terminal and run:
conda create -n myenv python=3.9Replace
myenvwith your environment name. - Activate the environment:
conda activate myenv
Step 2: Install Required Packages
conda install pandas seaborn geopandas matplotlib
You can also use a .yml or requirements.txt file:
- For a
.ymlfile:conda env create -f environment.yml - For a
requirements.txtfile:pip install -r requirements.txt
Troubleshooting Common Issues
Python 2.x Conflicts
If you have old Python 2.x installations:
- Ensure Anaconda takes precedence in your PATH. Run:
which pythonIf it points to an old version, edit your
~/.bashrc(for WSL) or~/.zshrc(for macOS):export PATH="~/anaconda3/bin:$PATH"
Virtual Environment Activation Issues
Run:
source ~/.bashrc # WSL/Linux
source ~/.zshrc # macOS
Package Installation Problems
For difficult installations, try using conda-forge:
conda install -c conda-forge geopandas
Testing Your Setup with a Python Script
Create a script named test_setup.py to verify the setup:
import pandas as pd
import seaborn as sns
import geopandas as gpd
import platform
import matplotlib.pyplot as plt
def test_packages():
data = pd.DataFrame({
'category': ['A', 'B', 'C'],
'values': [10, 20, 30]
})
sns.barplot(x='category', y='values', data=data)
plt.title("Test Plot")
plt.savefig("test_plot.png")
print("Plot generated successfully.")
def system_report():
report = {
"OS": platform.system(),
"Version": platform.version(),
"Python Version": platform.python_version(),
}
print("System report:", report)
return report
if __name__ == "__main__":
test_packages()
report = system_report()
with open("system_report.txt", "w") as f:
for key, value in report.items():
f.write(f"{key}: {value}\n")
print("System report saved.")
Run the script:
python test_setup.py
Installing PyCharm and Connecting to WSL
Step 1: Install PyCharm
- Download PyCharm from here.
- Follow the installation instructions.
Step 2: Activate PyCharm with Student Account
- Sign up for a free student license at JetBrains Student Program.
- Open PyCharm and log in using your JetBrains account.
Step 3: Connect PyCharm to WSL
- Go to File → Settings → Project → Python Interpreter.
- Click the gear icon, select Add → WSL, and choose the WSL Python interpreter.
Installing VSCode and Connecting to WSL
Step 1: Install VSCode
- Download VSCode from here.
- Follow the installation instructions.
Step 2: Install WSL Extension in VSCode
- Open the Extensions tab in VSCode.
- Search for Remote - WSL and install it.
Step 3: Connect VSCode to WSL
- Open a WSL terminal and navigate to your project folder.
- Run:
code . - VSCode will open, connected to WSL.
Step 4: Install Python Extension in VSCode
- Go to the Extensions tab.
- Search for Python (by Microsoft) and install it.
Adding Python Interpreter in PyCharm and VSCode
Adding Python Interpreter in PyCharm
- Go to File → Settings → Project → Python Interpreter.
- Click the gear icon, choose Add Interpreter, and select WSL.
Adding Python Interpreter in VSCode
- Open the Command Palette (
Ctrl+Shift+P). - Select Python: Select Interpreter.
- Choose the WSL Python interpreter.
Installing Python Packages in WSL and Extensions for VSCode
Installing Python in WSL
- Open your WSL terminal and run:
sudo apt install python3 python3-pip
Installing Development Tools in WSL
- Install essential build tools:
sudo apt install build-essential libssl-dev libffi-dev python3-dev
Installing Conda Packages
If using Conda, install packages like this:
conda install pandas seaborn geopandas matplotlib
Installing Python Extensions in VSCode
- In VSCode, go
to the Extensions tab and install:
- Python Extension (by Microsoft)
- Jupyter Extension (optional)
- Remote - WSL Extension (if not already installed)