-1

I am currently working solo on a very small simple python microservice. I started building this app, mostly by habit, in a virtual environment. As I started to get closer to the point where deployment considerations needed to be made, I started to realize that all of the dependencies I'd need to include in the container are already "contained" inside the virtual env.

In fact, as far as I've thought it through (which is admittedly miles from 'all the way,') for a python app, one could just deploy a virtual environment with installed dependencies preinstalled onto a server. As for x-axis scalability, the directory could be copied, no.

My question, then, is this:

Is this idea even feasible, or am I overlooking something? And if so, are there any advantages to using containers over virtual environments?

3
  • To whomever down-voted, please note that a virtual environment, in Python, is a type of project container, and not just a concept. If you understood this and still downvoted, please provide an argument...
    – Nate T
    May 20, 2021 at 9:40
  • 2
    I'm not the downvoted, but the trouble with "are there any advantages" questions is that the answer is always "yes", even if the answer is "here is a really insignificant advantage which makes no difference to the world". A better question would be to include the specific problem you're facing and why your current solution doesn't meet your needs. May 20, 2021 at 12:37
  • @philip Kendall Thank you for pointing that out. This wasn't meant to be a "which is better" question, but, as you said, the last sentence makes it look that way. I will try to reword it slightly to better frame the question without invalidating anyone else's content on the page.
    – Nate T
    May 21, 2021 at 1:43

2 Answers 2

2

Absolutely, virtual envs are a great option for isolating dependencies. But only for dependencies that are Python packages. You also need configuration management on the server: for the available Python versions, for native libraries, and for other tools that might be needed. And I don't think you should copy a virtualenv to a different system.

In contrast, a container let's you isolate all dependencies, except for the Linux kernel and of course external services.

In practice, either variant can be fine for deployment. Personally, I prefer using containers because this allows for more control, easier testing, and provides a security barrier between the application and the host system.

1
  • Thank you for taking the time to answer. In the specific instance about which I was wondering is a "meta-service" (helper-service) that will most likely only ever be used in development environment(s). All of our prod-env services use docker / kubernetes for containerization. It just didnt make sense to me at the time to reset dependencies & rebuild the entire environment when all I had to do was port the environment which I'd already built. The reason that I made the OP a bit overly vague, as I was sort of curious to see if anyone actually uses venv in this capacity.
    – Nate T
    May 21, 2021 at 1:37
0

There are limits how much the Python virtual environment can do. You cannot install the needed version of CUDA or Oracle database just with pip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.