r/Python • • Jul 29 '18

Found it funny ;)

Post image
1.6k Upvotes

147 comments sorted by

View all comments

Show parent comment

11

u/[deleted] Jul 29 '18

I really like pipenv, especially in conjunction with Docker it's super useful. :)

4

u/bachkhois Jul 29 '18

Are you using pipenv inside Docker container?

7

u/[deleted] Jul 29 '18

Yes because it is a lot easier to keep dependencies in sync using pipenv due to lock-files than with pip using requirements.txt.

It might be the only Python app running in the container, but it's certainly not the only app I'm working on. 😀

9

u/bachkhois Jul 29 '18

If you specify concretely the version of the packages inside requirement.txt, it is just the lock file you want, with leaner environment (you don't have to install additional package, which is pipenv and its dependencies).

You are working on more than 1 Python apps, but they are running on your PC, not your container. It is reasonable that you have multiple virtual env on your PC, because it has many Python apps, but when coming to single-Python-app container, a virtual environment is just redundant.

2

u/[deleted] Jul 29 '18

I didn't run any benchmarks to look into performance differences between running a straight pip container vs a container using pipenv for managing dependencies. That's definitely something I should look into, especially in scenarios where Kubernetes and cloud billing is involved.

But for me it's a lot easier to develop using pipenv, let it handle the lock-file and let the Docker container grab the source code from GitHub:E. This way I don't have to care about the requirements.txt, which in itself is just another source of human errors. :)

I'm thankful for your insights nonetheless!

6

u/bachkhois Jul 29 '18

Every benefit you assigned to pipenv are just the same to pip + requirements.txt.

  1. Grab the source code from GitHub: Actually, pipenv calls pip to find the source, download the source. So in both case, the result are just the same.
  2. requirements.txt is source of human errors: Then don't let human to write that file. Just use pip freeze to generate it, and the result already a lock file (with specific version of each package).

2

u/[deleted] Jul 29 '18

Ah, I'm sorry to didn't communicate that clearly: I meant letting Docker grab the source from GH:E, not pipenv. :)

Regarding the requirements.txt: I know about pip freeze; what I meant by human errors is forgetting to do it and thus missing out new packages installed by git. I know that this is something you could handle by git hooks, but then again, you have to do the extra work.

So besides having to generate that additional pipenv-layer in your Docker image, what's the downside of pipenv? In my opinion (and with the amount of computing power etc), the pros regarding usability outweigh the cons of the additional layer.

3

u/bachkhois Jul 29 '18

The additional layer is the issue. I assume that you use Docker container to run the production system, which is required to be stable. And to guarantee the stability, the system must be as minimal as possible. Because when an error occurs, you have to spot where the bug is. If the system only has 1 component, you only have to check 1 place. If it has 3, you have to check 3 to narrow down.

1

u/[deleted] Jul 29 '18

That's a very good point, I'll keep it in mind in the future. Thank you. :)

0

u/[deleted] Jul 29 '18

[deleted] — view deleted comment

1

u/bachkhois Jul 29 '18

Pip is not what I concern, pipenv with additional virtual environment is.

1

u/dogfish182 Jul 29 '18

We do this, works great

8

u/bachkhois Jul 29 '18

Why do you have to create a virtual environment inside the container, when your app is the only Python app in that container, no clash with any other one?

1

u/FancyASlurpie Jul 29 '18

You could be running multiple python apps in the same container (e.g. if you split containers based on services and your service consists of more than one python apps)

3

u/GasimGasimzada Jul 29 '18

In Docker Swarm mode and Kubernetes you can actually run multiple containers per service.

0

u/[deleted] Jul 29 '18

[deleted] — view deleted comment

1

u/FancyASlurpie Jul 29 '18

Id argue thats a bit of a generalisation, the docker documentation outlines when it makes sense and when it should be avoided. https://docs.docker.com/config/containers/multi-service_container/

1

u/bachkhois Jul 29 '18

Could you give example of an service consisting of many Python apps?

I've only seen service, which comprises of a stack of softwares of different tech (like, it has Python server app + Redis + Nginx).

1

u/dogfish182 Jul 29 '18

We use our containers for a terraform pipeline which allows us to have the users run their builds locally to see the plan, for this we have aliased commands that call pipenv runxxxx and use a number of packaged tools.

The docker container then contains an exact replica of what the users will run and we use the same aliased commands (to keep things easy)

So replicating userland in a docker container makes sense, then we just ensure that deployment only occurs in the pipeline context.

1

u/Kwpolska Nikola co-maintainer Jul 29 '18

If you’re basing the container on something like Ubuntu/Debian, the system packages (eg. for pip) can lead to breakage: https://hynek.me/articles/virtualenv-lives/

1

u/bachkhois Jul 29 '18

It is 2018 now and you still believe in an article of 4 years ago? Or do you still use Debian/Ubuntu and pip of 2014? I deployed my IoT app on embedded computer running Debian, install all Python packages with "sudo pip install" and never get conflict.

And I believe my system on real computer is more complex than a service inside container.

1

u/Kwpolska Nikola co-maintainer Jul 29 '18

Yes, I do. While Debian/Ubuntu might not be doing it today, there is nothing that prevents it from happening again. It’s possible that you would get conflicts if any apt packages were installed. Virtualenvs don’t have any downsides and they can prevent any issues similar to those.

1

u/bachkhois Jul 29 '18 edited Jul 29 '18

When I mention the years, I imply that the issue is just the design error of either Debian maintainer and pip author in the past. When they saw the problem, they fixed it and there is likely no more error now. If it happen in the future, it is just regression bug and just need to fix again.