Consistent Development Environment With Devcontainers
The problem
You’ve just cloned a repository and you want to run the project. So you spend the next few hours installing dependencies, setting up the environment, and debugging why it doesn’t work.
If there was only a way to ensure that everyone has the same setup…
The solution
Devcontainers provide a containerized development environment, ensuring consistency across different setups. Everyone* can have the same environment, regardless of the operating system, Python version, or installed libraries.
You’ve created some project and you want to share it with others. You can’t expect everyone to have the same setup as you do. Some might have different versions of Python (I can’t count how many times I’ve been juggling between Python 3.6 and 3.10), different versions of libraries, or even different operating systems. Then there are external dependencies, very common in the RShiny world, that might not be available on all systems. Often it’s not your fault, the project depends on one library that you installed with apt/brew install
long time ago and you don’t even remember it.
Devcontainers solve this problem by providing a consistent development environment. You can define the environment in devcontainer.json
/ Dockerfile
, include in the repository, and everyone can easily recreate the same environment. By adding apt install
to the Dockerfile
, you can ensure that all dependencies are installed and you can keep track of them. No more “it works on my machine” excuses.
Modern development tools like VS Code, JetBrains / PyCharm, and GitHub Codespaces support Devcontainers out of the box. There are also tools like devpod that allow you to run Devcontainers in any environment. You have a little project that you want to run locally? Sure. You have a big project that you want to run on a powerful server? No problem, devpod will spin up AWS/GCP/Azure machine for you and run the Devcontainer there.
* Windows and linux users will have the exact same environment. Mac users, who have ARM/Apple Silicon (M1/M2/M3) chip, will have a slightly different environment. This is not an issue for tapyr
/ most Python projects, but it’s worth mentioning.
Regarding external dependencies, e.g., to use pycairo
you may need to put the following in your devcontainer.json
:
"postCreateCommand": "sudo apt update && sudo apt install libcairo2-dev -y && uv sync && uv run playwright install --with-deps",
Devcontainers in VS Code
Follow the introduction to tapyr blog post to learn how to set up tapyr
project in VS Code with Devcontainers. Then we recommend you reading the official VS Code | Developing inside a Container documentation to learn more about Devcontainers.