Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason not to check in the virtualenv environment along with the source code of a python project?

I'm following the instructions for setting up to work with Python on a Mac (http://docs.python-guide.org/en/latest/starting/install/osx/)

It suggests to store the virtual environment created by virtualenv in the project directory... which is of course a git repo.

Is there any reason not to add the virtualenv to the git repo? It seems the natural thing to do, but ...

like image 828
GreenAsJade Avatar asked Nov 01 '13 11:11

GreenAsJade


People also ask

How do you check the virtual environment in python?

Check the $VIRTUAL_ENV environment variable. The $VIRTUAL_ENV environment variable contains the virtual environment's directory when in an active virtual environment. Once you run deactivate / leave the virtual environment, the $VIRTUAL_ENV variable will be cleared/empty.

Is virtual environment necessary for python?

It is generally good to have one new virtual environment for every Python based project you work on. So the dependencies of every project are isolated from the system and each other. How does a virtual environment work?

Why virtualenv is not recognized?

Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe . If not, uninstall will pip uninstall virtualenv and install again.

Is virtual environment necessary?

VirtualEnv helps you create a Local Environment(not System wide) Specific to the Project you are working upon. Hence, As you start working on Multiple projects, your projects would have different Dependencies (e.g different Django versions) hence you would need a different virtual Environment for each Project.


1 Answers

Always try to check in the source, not the result of running a process.

A virtualenv is rather platform specific; a Windows virtualenv may require different binaries than one created on Linux. The paths in the script files will almost certainly use absolute paths, not relative paths, tying a virtualenv to a specific location on your harddisk.

Instead, check in instructions on how to recreate a virtualenv. Include the commands, and use tools like pip, zc.buildout or Pipenv to let others recreate the right environment for their platform.

pip lets you install packages into a virtualenv with a requirements.txt file. You'd commit that file. zc.buildout lets you define complex build configurations in .cfg files. Commit those. Pipenv tracks the top level dependencies in Pipfile and creates a Pipenv.lock file for perfectly reproducible environments, check in these two files, etc.

like image 125
Martijn Pieters Avatar answered Oct 08 '22 09:10

Martijn Pieters