Use Jupyter Notebooks
CodeCanvas provides support for Jupyter notebooks out of the box – everything works as long as your dev environment template is properly configured. This topic provides one way to set up a template for working with Jupyter notebooks. You can adjust this workflow to fit your project.
Prepare a template
Start creating a dev environment template as described in Create Template.
Provide the following Basic settings:
Repositories – select the repository that contains your Jupyter notebooks.
IDE – select Visual Studio Code.
Switch to the Project settings section and in VS Code Extensions, add the following extension IDs:
ms-toolsai.jupyter
ms-python.python
Switch to the Lifecycle section and enable the On initialization script. Add the script below to the Script field. This script prepares a virtual environment and installs the necessary Python packages.
#!/bin/bash # Set the project directory variable PROJECT_DIR="./MY-PROJECT-DIR" # replace MY-PROJECT-DIR with your actual project directory # Check if the project directory exists if [ ! -d "$PROJECT_DIR" ]; then echo "Project directory not found: $PROJECT_DIR" exit 1 fi cd "$PROJECT_DIR" # Create a virtual environment python3 -m venv .venv || { echo "Failed to create virtual environment"; exit 1; } # Activate the virtual environment source .venv/bin/activate || { echo "Failed to activate virtual environment"; exit 1; } # Upgrade pip and install required packages pip install --upgrade pip pip install ipykernel pip install -r requirements.txt || { echo "Failed to install dependencies"; exit 1; } echo "Virtual environment created and dependencies installed successfully."Save the template and create a dev environment based on it.
Work with the Jupyter notebook
Once the dev environment is running, open a
.ipynb
file in VS Code. A run icon will appear next to Python code cells.Click the run icon. VS Code will prompt you to select a kernel. Select the virtual environment created by your script. You should now be able to run the notebook.