Some time ago I started developing an application. According to numerous tips, the development is carried out in a virtual environment, which made me think about the question - how will the finished application be deployed on target machines? Do I need to package the application + dependent packages, or transfer the package itself + requirements.txt? Venv not used in production? What is then the advantage of venv? Why not just install dependencies into the system during development?

Closed due to the fact that the issue is too general for participants jfs , aleksandr barakin , fori1ton , Nick Volynkin 26 Apr '16 at 4:56 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    How to deploy applications — this is too broad a topic (and the part related to Python is relatively small, but also vast in general — Python can be used in many contexts). In different cases you can use: one executable file (eg, packaged in PyInstaller), pip install (for Python programmers), git push , curl https://.../install.sh | sh curl https://.../install.sh | sh (for adventurers), system packages (eg, fpm, ppa on Ubuntu), docker containers, Fabric, Salt, Ansible, etc. etc. Specify your question: what kind of application, who is the user, what specific requirements. - jfs
  • Virtual environment allows you to isolate dependencies. Situation: one project requires the first version of library A, and another - the second version of the same library, what will you do? Every time to update it / downgrade? Obviously, this is not convenient. With virtual environments, everything is simple - we create one per project and the head does not hurt. It also allows you not to litter the global environment. - Pavel Karateev
  • @jfs I did not ask in general about the deployment of applications, but about the deployment of exactly python-applications. I created the application in a virtual environment, what next? Is it possible to pack the environment this pythonic-way? And burden users with virtual environments? - aryndin
  • @PavelKarateev Suppose there are X and Y programs in PyPi, with a different set of dependencies, and I want to use both, should I be prudent and put venv for each of them? After all, they may conflict dependency? How to solve such problems with python? - aryndin
  • one
    @ jumpjet67 I’m telling you about python applications — only a small part of the deployment is unique to Python. If you do not specify the task, then you can write several books on this topic. - jfs

1 answer 1

Firstly, venv is often used in production, including even on low-cost hosting, and on a dedicated server, no one will interfere with its use.

And how to deploy applications is a vast topic. Someone is using docker containers or something like that. In the simplest case, the package + requirements.txt is enough, because there you can specify the versions of libraries you need.

venv is good because you can make your environment for each project. Otherwise, when switching from project to project, you would need to reinstall the libraries of the required versions.