Creating a GitHub Codespace for a Python Project
Part 1: Use the Starter Codespace
Part 2: Run the Codespace
- Click the “Code” button, and then click the “Codespaces” tab.
- Click the “Create Codespace on Main” button. GitHub will create a Codespace, which will take a while.
- Once the Codespace is ready, it will open in a new browser tab with an integrated development environment (IDE) powered by Visual Studio Code.
Part 3: Install libraries in the Codespace
- Open the terminal in the Codespace by clicking “Terminal” in the top menu and selecting “New Terminal.”
- If your project has a
requirements.txt
file, install the required packages using the following command:pip install -r requirements.txt
Part 4: Experiment with Python
- Open
app.py
and attempt to run the script. You can also run the script Jupyter notebook-style by executing cells.
Part 5: Shut down the Codespace
- You have a free limit of around 60 hours per month.
- If you have a Pro account, or a credit card on file, to avoid charges, set the spending limit in the settings of your account.
- Always Stop the Codespace when you are done. You can do this by clicking on the bottom left hand corner of the editor where it says, “Codespaces,” and select “Stop Codespace.”
You now have a fully functional GitHub Codespace for your Python project. You can use the browser-based IDE to write, run, and debug your Python code, as well as commit and push changes to the remote repository. If you continue using the codespace, it is recommended to create a fork of the repository so that you can save changes to your scripts! You can see how to do this in the video.