0

I'm relatively new to the world of python, so I apologize if this is a stupid question.

I'm having some trouble discerning at what level I should be creating my virtual environment. Using a trivial example:

project
    │   README.txt
    │   setup.py     
    |   venv ** should this go here **
    │
    └───package1Name
    |   |   venv ** or here **
    │   ...    
    └───package2Name
    |   |   venv ** and here **
        ...
pim
  • 12,019
  • 6
  • 66
  • 69

2 Answers2

2

Think about it like this - Your whole project is a single environment, well because you would want it to be separated from other things in your system. Now within your environment, things(modules) must be interacting with each other and therefore each of the modules can't really be in different environments.

In conclusion, the venv goes at the top

project
    │   README.txt
    │   setup.py     
    |   venv ** goes here **
    │
    └───module1Name
    |   |  
    │   ...    
    └───module2Name
    |   |   
        ...
Raunaq Jain
  • 917
  • 7
  • 13
  • Do I have the semantics correct? The top-level directory would be the project, and immediate subdirs are modules? – pim Sep 14 '18 at 19:07
  • I think I answered my own question from the python docs, "A module is a file containing Python definitions and statements. " -- to that effect I would say that a collection of modules is a package? – pim Sep 14 '18 at 19:09
  • Your structure is perfectly okay – Raunaq Jain Sep 14 '18 at 19:10
  • Yes, you can say so. Modules are just python files which can be imported from other pieces of code. – Raunaq Jain Sep 14 '18 at 19:11
0

In python, modules don't work quite this way, normally is one virtualenv per project, (but is not a fixed rule).

From the python documentation about modules:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable name.