Complete Tutorial: Setting Up a Remote Development Environment for Python on Ubuntu 24.04

This tutorial guides students through setting up a remote Python development environment on an Ubuntu 24.04 server. Students will use their laptops to write and edit Python code on the remote server using Visual Studio Code (VS Code) with SSH integration. Students will also install GitHub Copilot to assist with coding. The project involves writing a Python script to process the text of Alice in Wonderland and output a sorted list of unique words with their counts.


1. Setting Up the Environment

1.1. Prepare the Remote Server

  1. Update the Server:
    sudo apt update && sudo apt upgrade -y
  2. Install Basic Tools:
    sudo apt install -y git curl python3 python3-pip

1.2. Configure SSH Access

On Your Laptop:

  1. Generate an SSH Key:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    • Save the key in the default location (~/.ssh/id_rsa).
    • Press Enter for no passphrase (or set one if desired).
  2. Copy the Public Key to the Server:
    ssh-copy-id username@server_ip
  3. Test the Connection:
    ssh username@server_ip You should be logged into the server without a password.

1.3. Install VS Code and Remote Extensions

On Your Laptop:

  1. Install VS Code:
  2. Install the Remote-SSH Extension:
    • Open VS Code.
    • Go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS).
    • Search for Remote - SSH and install it.
  3. Configure the Remote Connection:
    • Press Ctrl+Shift+P (Cmd+Shift+P on macOS) and type Remote-SSH: Add New SSH Host.
    • Enter the connection string:
      username@server_ip
    • Select the SSH configuration file location (e.g., ~/.ssh/config).
  4. Connect to the Remote Server:
    • From the Remote Explorer view in VS Code, connect to the server.
    • Once connected, VS Code will open a remote workspace.

1.4. Install GitHub Copilot

  1. Install the GitHub Copilot Extension:
    • In VS Code, search for “GitHub Copilot” in the Extensions view and install it.
  2. Sign In to GitHub:
    • Follow the prompts to authenticate GitHub Copilot.
  3. Test Copilot:
    • Open a new file and type a comment like # Function to add two numbers. Observe how Copilot suggests code snippets.

2. Setting Up the Development Environment

2.1. Create a Project Directory

  1. Navigate to the Workspace:
    mkdir -p ~/projects/alice && cd ~/projects/alice
  2. Initialize a Git Repository:
    git init
  3. Install Python Virtual Environment Tool:
    sudo apt install -y python3-venv
  4. Create a Virtual Environment:
    python3 -m venv venv source venv/bin/activate
  5. Install Required Python Libraries:
    pip install --upgrade pip

3. Write the Python Program with Copilot

3.1. Fetch Alice in Wonderland

Download the text file from Project Gutenberg:

curl -o alice.txt https://www.gutenberg.org/files/11/11-0.txt

3.2. Create the Python Script

  1. Create a Python File: In VS Code, create a file named alice_word_count.py.
  2. Use Copilot to Assist with Writing the Code:
    Hit Command-I and ask: “Write python code to read alice.txt and count unique words, printing a list of unique words and their counts.”
from collections import Counter
import re

def count_unique_words(file_path):
with open(file_path, 'r') as file:
text = file.read().lower()
words = re.findall(r'\b\w+\b', text)
word_counts = Counter(words)

for word, count in word_counts.items():
print(f"{word}: {count}")

if __name__ == "__main__":
count_unique_words('alice.txt')

  1. Save the File: Save alice_word_count.py in the project directory.

3.3. Run the Python Script

  1. Run the Script: Execute the program:
    python3 alice_word_count.py
  2. Check the Output: The script should display a sorted list of unique words with their counts.

3.4. Use Copilot to add comments.

3.4. Use Copilot to rewrite to sort by word counts from high to low.


4. Save the Project to GitHub

4.1. Set Up SSH for GitHub

  1. Generate an SSH Key (if not already done):
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. Add the SSH Key to GitHub:
    • Copy the key:
      cat ~/.ssh/id_rsa.pub
    • Log in to GitHub, go to Settings > SSH and GPG keys, and add the key.
  3. Test the Connection:
    ssh -T git@github.com

4.2. Push the Project to GitHub

  1. Create a New Repository on GitHub:
  2. Add the Repository as a Remote:
    git init
    git remote add origin git@github.com:<username>/alice-word-count-python.git
  3. Commit and Push:
    git add .
    git commit -m "Initial commit: Alice word count project"
    git branch -M main
    git push -u origin main
  4. Verify on GitHub: Visit the repository URL to confirm your files are uploaded.

5. Debugging and Enhancements

  • Enhancements with Copilot:
    • Add stopword filtering.
    • Include functionality to handle case sensitivity better.
    • Save results to a file instead of printing to the console.
  • Test with Smaller Datasets:
    • Create a smaller text file for faster debugging.

This tutorial provides a comprehensive guide to set up a Python development environment on a remote Ubuntu server, with a practical project to demonstrate coding and GitHub Copilot’s capabilities.

Scroll to Top