DEV Community

Discussion on: Dead Simple Python: Virtual Environments and pip

 
tomekbuszewski profile image
Tomek Buszewski

Hey Jason, thanks for the great write-up! It certainly solves a lot of questions for me. But one is still there – what to do when I have databases and I don't want to have pq, mysql and mongo installed on my system in various versions?

Thread Thread
 
codemouse92 profile image
Jason C. McDonald • Edited

Assuming SQLite is not an option, this is exactly the sort of scenario where Docker is a good solution: you aren't just needing the sandbox the Python environment itself (virtual environment), but the actual system environment.

Virtual environments really become extra helpful here, too, because it simplifies your Dockerfiles. Assuming your Python project has a requirements.txt file, you'd only need the following:

RUN python3 -m venv venv && \
    venv/bin/pip install -r requirements.txt

You'll note, I had no need to "activate" the virtual environment. You can just use the venv's binaries directly; they know to use the virtual environment.