2

I am wondering whether having an (untracked) virtual environment folder inside of your local Git clone is considered bad directory structure.

It seems cleaner to place the repository and the virtual environment in a single folder, but that is also more awkward and bulky.

Here are the two options I am considering:

A.

git_clone/

    virtual-environment/

B.

name_of_project/

    git_clone/

    virtual-environment/

This question is similar to this one, but for users/contributors instead of maintainers.

Is it bad to have my virtualenv directory inside my git repository?

Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
user82841
  • 25
  • 3
  • 1
    This is really an opinion question, but I tend to like my environments in `/home/myuser/envs/` and working copies in `/home/myuser/build` (or whatever). – AKX Dec 30 '19 at 18:09
  • Is separating the environments and working copies an advantage for you? – user82841 Dec 30 '19 at 18:13
  • Untracked as in ignored with .gitignore, right? – Ry- Dec 30 '19 at 18:19
  • I separate the virtual env from the local Git clone. In my opinion, it is cleaner to have only the req.txt in the repository. – Kingindanord Dec 31 '19 at 21:24

2 Answers2

0

To decide, I answer the question "will I reuse my virtual env in multiple projects?" If yes, then I place the virtual env outside the working tree. If no, then I place the virtual env inside the working tree.

As for reuse, projects often do not depend on the same set of libraries. Even when they do depend on the same set of libraries, projects depend on specific versions of libraries. So, having dedicated virtual env inside working tree is a simple way to avoid issues due to incorrect or extraneous dependencies in above situations.

In terms of cost, while dedicated virtual envs can lead to duplicates, most of my virtual envs are in the order of few 10s of MBs; a small price in terms of space to avoid the hassles due to incorrect dependencies. If extra space is indeed an issue, then virtual envs can be created, used, and deleted as and when required given how easy it is to create virtual envs (e.g., via pip and requirements.txt).

-1

Copy the requirements.txt out into a parent folder and use PIP there. PIP is like NPM, it installs dependencies directly into the OS (unlike snapd), and while it shouldn't matter, better to be safe than sorry!

Also, fair warning to you that opinion based questions aren't allowed on StackOverflow, so you might get downvoted. While not technically a good question, I do like it. +1

amyiris
  • 113
  • 14
  • It installs dependencies into a virtual environment, not the OS, if you’re using a virtual environment like in the question (and like you should). Installing packages globally with npm instead of the default project-local `node_modules` is similarly bad practice. – Ry- Dec 30 '19 at 19:03