Search code examples
pythongitgithubrepositorygit-commit

how to commit virtual envinroment


I have a Python code with virtual env and libraries on my local but in GitHub repository there is no virtual env/libraries.

I removed virtual environment from git-ignore but still the libraries are not getting committed to repository and when I clone it to another system I don't have it.

What is the best practice to commit env and libraries to repository or better to install it again on each computer. If it's acceptable to commit virtual env, can you please advise how to do it.


Solution

  • I personally do it by installing through requirements and push the requirements to the repo. Eg:

    pip3 freeze > requirements.txt
    

    Will make a list of all packages and libraries that you've installed in the virtual environment (assuming you're in the environment of course, and not transferred any from the global environment). If you push the requirements.txt file, you can create a new virtual environment as usual and install the requirements:

    pip3 install -r requirements.txt