[Django]-Do we need to upload virtual env on github too?

37๐Ÿ‘

โœ…

As was mentioned in a comment it is standard to do this through a requirements.txt file instead of including the virtualenv itself.

You can easily generate this file with the following:
pip freeze > requirements.txt
You can then install the virtualenv packages on the target machine with:
pip install -r requirements.txt

It is important to note that including the virtualenv will often not work at all as it may contain full paths for your local system. It is much better to use a requirements.txt file.

๐Ÿ‘คDaniel Hill

7๐Ÿ‘

No โ€“ although the environment is 100% there, if someone else where to pull it down the path environment hasnโ€™t been exported not to mention Python version discrepancies will likely crop up.

The best thing to do is to create what is known as a requirements.txt file.

When you have created your environment, you can pip install this and pip install that. Youโ€™ll start to built a number of project specific dependencies.

Once you start to build up a number of project dependencies I would then freeze your local python environment (analogoues to a package.json for node.js package dependency management). I would recommend doing the following in your terminal:

(local_python_environment) $ pip install django && pip freeze > requirements.txt

(local_python_environment) $ pip install requests && pip freeze > requirements.txt

That is to say, freeze your environment to a requirements.txt file every time a new dependency is installed.

Once a collaborator pulls down your project โ€“ they can then install a fresh python environment:

$ python3 -m venv local_python_environment

(* Please use Python 3 and not Python 2!)

And then activate that environment and install from your requirements.txt which you have included in your version control:

$ source local_python_environment/bin/activate

(local_python_environment) $ pip install -r requirements.txt

Excluding your virtual environment is probably analogous to ignoring node_modules! ๐Ÿ™‚

๐Ÿ‘คuser10215593

2๐Ÿ‘

No Its not necessary to upload virtualenv file on github. and even some time when you push your code to github then it ignore python file only if add into ignore.

Virtual Environment
Basically virtual environment is nothing but itis a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most of the Python developers use. Apart from that you can add requirement.txt file into your project.

Requirement.txt
It is file that tells us to which library and application are need to run this application. you can add requirement.txt file with this simple command.

 pip freeze > requirements.txt

After run this command all application and library add in this file. and if you make your project without activate any virtualenv then python automatically use system environment variable it will also add all the file that not necessary for your project.

๐Ÿ‘คAvvy Paul

0๐Ÿ‘

You should add the virtualenv in your gitignore. Infact github has a recommended format for python, which files should be added and which shouldnโ€™t

Github recommendation for gitignore

๐Ÿ‘คArghya Saha

Leave a comment