5 ms·
Unfortunately in many (most?) cases I've seen the prescribed deployment practice for Python software is to use virtualenv (or some variant of it). Python depend
by avian 7y ago
Unfortunately in many (most?) cases I've seen the prescribed deployment practice for Python software is to use virtualenv (or some variant of it). Python dependencies are to be handled exclusively via pip (requirements.txt, install_requires in setup.py, etc.) and using distro-packaged Python modules is frowned upon because they are considered to be outdated.
I'm not saying that's the best practice. Personally I like to use distro-packaged stuff as much as possible because it's less volatile and tends to go through some more review than things on PyPI. But the virtualenv/pip exclusive method does seem to prevail in the field in my experience, so the advice to just use Alpine packages isn't useful in many cases.
- jontaydev 7y agoIt is best practice, but you probably don’t need virtualenv if you’re deploying a single application in a docker container.
- brummm 7y agoMessing with the system python without using some form of virtual environment is a recipe for disaster.
- dkarp 7y agoIt's a docker box, you're already inside some form of virtual environment
- kevin_thibedeau 7y agoDebian distros have a separate dist-packages directory for system libs. You can do whatever you want in site-packages. It is effectively like a default virtualenv when operating in a container.
- penagwin 7y agoIn the docker container you ARE the system python version. In fact many docker best practices would say that preferably only 1 application is running, and that would be your application.
- viraptor 7y agoIt's still not safe. For example there was a conflict one day between awscli, urllib and some system tool (apt?) which led to a broken (apt fails) system if you just "pip install awscli" globally. Even in docker image, you still need virtualenv to be safe (or use only global distro packages).
- fjp 7y agoCould you elaborate on why? I worked at a co that almost exclusively ran Alpine containers with a single Python app. No use of virtualenv. Never experienced any hangups with this.
- viraptor 7y agoLooked up the issue and it was cloud-init, not apt that failed. Here are the details: https://github.com/aws/aws-cli/issues/3678 https://github.com/aws/aws-cli/issues/3678 In one sentence: "Installing the latest aws-cli on an image is preventing new AMIs based on that image from booting due to the above issue with urllib3." While this specific issue wouldn't affect docker images since you normally don't run cloud-init on them, it's just luck that it wasn't some other utility affected instead. Next time it can affect docker images too.
- kortilla 7y agoWhy do you have cloud-init in a container?
- markbnj 7y agoSame here, and I'm curious to know why some think virtualenv is required in a container, as opposed to just starting with am image containing a clean python install and adding what you need.
- viraptor 7y agoI linked the example here https://news.ycombinator.com/item?id=22186046 https://news.ycombinator.com/item?id=22186046 But tlrd is: if you "apt install some-utility", then "pip install something else", you may have upgraded packages that some-utility relies on but is not compatible with the new version anymore.
- pid_0 7y agoNot in docker. The entire point of docker is isolation so when you use something like python3.7-slim, its fine to use the system python. Thats the whole point of using the image. Now you still want to run and install pip packages as a non-root user of course, but you don't need a virtualenv in docker.
- dkarp 7y agoAbsolutely agree. Which is why I don't use Alpine linux for python projects and wouldn't recommend anyone else does. In the article, they are only using pandas and not using a requirements.txt file. So it's a pretty perfect case to just use apk. In cases where you don't need many packages, you can still use Alpine if you would like without most of the downsides mentioned in the article.
- swiley 7y agoI write a decent amount of python on alpine, in general I stick to the standard library and occasionally something like pyserial, sqlite, or numpy for specific things. IMO this attitude of pulling in dozens of packages with pip is pretty dangerous, I don’t care which language you’re using.