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

  1. Prerequisites
  2. Installation on Windows with WSL
  3. Installation on macOS
  4. Creating and Using Virtual Environments
  5. Troubleshooting Common Issues
  6. Testing Your Setup with a Python Script
  7. Installing PyCharm and Connecting to WSL
  8. Installing VSCode and Connecting to WSL
  9. Adding Python Interpreter in PyCharm and VSCode
  10. 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)

  1. Open PowerShell as Administrator.
  2. Run the following command:
    wsl --install
    
  3. Restart your computer when prompted.
  4. Open Ubuntu from the Start menu and set up a username and password for WSL.

Step 2: Install Anaconda on WSL

  1. Download the Anaconda installer:
    wget https://repo.anaconda.com/archive/Anaconda3-latest-Linux-x86_64.sh
    
  2. Run the installer:
    bash Anaconda3-latest-Linux-x86_64.sh
    
  3. Follow the prompts and answer yes when asked to initialize Anaconda.
  4. Restart your WSL terminal or run:
    source ~/.bashrc
    

Verify Anaconda installation:

conda --version

Back to Top


Installation on macOS

Step 1: Uninstall Old Python Versions (if necessary)

  1. Open Terminal.
  2. 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

  1. Download the Anaconda installer from the official website.
  2. Open Terminal and navigate to your Downloads folder:
    cd ~/Downloads
    
  3. Run the installer:
    bash Anaconda3-latest-MacOSX-x86_64.sh
    
  4. Close and reopen the Terminal, then verify the installation:
    conda --version
    

Back to Top


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

  1. Open your terminal and run:
    conda create -n myenv python=3.9
    

    Replace myenv with your environment name.

  2. 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 .yml file:
     conda env create -f environment.yml
    
  • For a requirements.txt file:
     pip install -r requirements.txt
    

Back to Top


Troubleshooting Common Issues

Python 2.x Conflicts

If you have old Python 2.x installations:

  1. Ensure Anaconda takes precedence in your PATH. Run:
    which python
    

    If 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

Back to Top


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

Back to Top


Installing PyCharm and Connecting to WSL

Step 1: Install PyCharm

  1. Download PyCharm from here.
  2. Follow the installation instructions.

Step 2: Activate PyCharm with Student Account

  1. Sign up for a free student license at JetBrains Student Program.
  2. Open PyCharm and log in using your JetBrains account.

Step 3: Connect PyCharm to WSL

  1. Go to FileSettingsProjectPython Interpreter.
  2. Click the gear icon, select AddWSL, and choose the WSL Python interpreter.

Back to Top


Installing VSCode and Connecting to WSL

Step 1: Install VSCode

  1. Download VSCode from here.
  2. Follow the installation instructions.

Step 2: Install WSL Extension in VSCode

  1. Open the Extensions tab in VSCode.
  2. Search for Remote - WSL and install it.

Step 3: Connect VSCode to WSL

  1. Open a WSL terminal and navigate to your project folder.
  2. Run:
    code .
    
  3. VSCode will open, connected to WSL.

Step 4: Install Python Extension in VSCode

  1. Go to the Extensions tab.
  2. Search for Python (by Microsoft) and install it.

Back to Top


Adding Python Interpreter in PyCharm and VSCode

Adding Python Interpreter in PyCharm

  1. Go to FileSettingsProjectPython Interpreter.
  2. Click the gear icon, choose Add Interpreter, and select WSL.

Adding Python Interpreter in VSCode

  1. Open the Command Palette (Ctrl+Shift+P).
  2. Select Python: Select Interpreter.
  3. Choose the WSL Python interpreter.

Back to Top


Installing Python Packages in WSL and Extensions for VSCode

Installing Python in WSL

  1. Open your WSL terminal and run:
    sudo apt install python3 python3-pip
    

Installing Development Tools in WSL

  1. 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

  1. In VSCode, go

to the Extensions tab and install:

  • Python Extension (by Microsoft)
  • Jupyter Extension (optional)
  • Remote - WSL Extension (if not already installed)

Back to Top


This site uses Just the Docs, a documentation theme for Jekyll.