Getting Started with Python
Python is fully supported on Devboxes and Repositories. It leverages Docker to run a configurable Python container, while also bringing IntelliSense and support for Python package managers.
In this tutorial, we will showcase two different approaches you can use to get started with Python in CodeSandbox: starting from a template or importing an existing Python project.
Starting from a template
CodeSandbox provides a growing collection of Python templates that may be useful depending on your use case.
In case you want a fresh, blank environment to start building a project from scratch, you can use our Python starter (opens in a new tab). Otherwise, you will find our existing Python templates in the "Python" tab of the template library (opens in a new tab).
After forking one of these templates, you will probably want to open a terminal (which you can find under DevTools, on the top right) to run python
commands.
Importing an existing repository
You can also import one of your existing Python repositories from GitHub into CodeSandbox by following the steps below.
1. Import repository
From the CodeSandbox dashboard, click "Import from GitHub" and input the URL of your repository. If you are missing the required permissions, you should get a prompt asking you to update them.
2. Rebuild the container
As mentioned above, CodeSandbox relies on a Dockerfile to run Python.
After importing your repository, you won't be able to immediately run python
commands. First, you need to rebuild the container.
To do that, open any .py
file and you will see a prompt appear, asking if you want to create a Dockerfile. Click "Create Dockerfile".
CodeSandbox will create this file and set up Python. The first time when you do this step, it can take a while. However, after this setup, we will create a memory snapshot of the VM, which will ensure that the following VM loads (& clones!) will be fast.
3. Use the container
Now that the container has been built, all your new terminal sessions will be executed from inside this container, which is running Python. You can test this by opening a new terminal, and verifying that python
is installed.