Why would you create a requirements.txt file in a Python virtual environment?

I downloaded a Python project and contains both a virtual environment and a requirements.txt file. Why do you need both? As far as I know, virtual environments already contain the required modules. Any idea when and why this combination would be useful?

+3


source to share


2 answers


As long as it is technically possible, I find no reason for this. Having both is confusing because it is unclear which one is the "boss". And you should (or shouldn't?) Worry about consistency between the installed packages and the requirements.txt file.

Also venv and installed packages are in many cases dependent on the underlying OS, they have binaries, different layouts, etc. It is generally recommended to write os-independent code.



In general, I would stick with the requirements .txt file and remove any venv folder from the project repo.

+5


source


You cannot distribute the virtualenv directory in your project because the content may differ depending on the target operating system and operating system version. In particular, virtualenv, which includes libraries with compiled components installed on Ubuntu 14.04, will differ from the equivalent virtualenv installed on Ubuntu 16.04.



Instead, you must distribute your requirements.txt

file (just a convention, you can use any filename you want) so that the end user can recreate the virtualenv on their machine.

+1


source







All Articles