Why use venv at all when there is docker?


I am fairly new to Django so sorry if this is a silly question but I can’t find a good answer online.

Every tutorial/guide I have read about Django so far always starts with setting up a project using something like venv and then containerizing it.

I don’t really understand why?

It’s reasonably straightforward to set up a boilerplate docker composer file - or similar - for Django and then just start developing. You can update the requirements.txt file and log into each container as needed to do things like run migrations or the Django shell.

This also means there is no need to install anything on my dev system other than docker.

I am working on my first proper Django project at the moment and I haven’t yet gone anywhere near a local virtual machine/venv

Am I missing something, or is a local virtual environment like venv mostly redundant these days?

As an aside, does something like DDEV exist in the python/Django world?

In general, when you’re talking about tutorials, you want to avoid as many “environmental” issues as you possibly can. This also includes trying to be agnostic about things like IDEs as well. Not everyone works in an environment where Docker is guaranteed available. The focus on a Django tutorial should be on learning Django - not “installing software ‘A’, ‘B’, and ‘C’ to get your development environment to look like what we want it to look like.” There are still a lot of software developers that have never worked with Docker.

It’s not redundant for us. We don’t do a “venv per project”, we generally create a venv for a set of related projects and processes. (Granted, these projects are a particular niche-case, but it’s what we do. We do also use Docker-based development environments - but not for everything.)

It is not necessary… if you don’t need it.

I’d say it is still much easier to use venv for local development when it comes to automatic IDE support, debugging setup, etc.