2

I am looking at debian and virtualenv and I was wondering what directory structure people would recommend. From my reading it seems something like this is a good idea:

Code:

var/www/<projectname>/src

Virtualenv:

var/www/<projectname>/venv

Can anyone do any better on that, or point me in the right direction please?

Jimmy
  • 10,619
  • 22
  • 84
  • 170

2 Answers2

2

on our company each user has a Projects directory under it's home, something like:

/home/username/Projects

This directory holds all current projects, let's say you want to check the Foogram project, it would be at:

/home/username/Projects/Foogram

The virtualenv is created inside the project folder, as a .venv dir, thus the following directory contains the virtualenv:

/home/username/Projects/Foogram/.venv

Now, you will most surely want to use a DVCS (distributed version control system), like Git or Mercurial. Putting the venv and binary files under the DVCS is generally a bad idea, so you should add a rule to avoid the .venv dir being added to the repository. Using Mercurial you can achieve this by editing the .hgignore file. You can do that by doing:

nano /home/username/Projects/Foogram/.hgignore

Add the following line:

.venv/*

This will ignore the .venv directory and everything inside it. You should probably also take your time to add the following rules to the .hgignore:

*.pyc
*.*~
*.log
*.orig

These rules will help you keep your repository sane.

rafgoncalves
  • 186
  • 6
1

Your proposed directories would be fine if you intend to do a simple project. For larger or long term projects, you will likely want to use some sort of SCM tool such as git or mercurial. If you do want to use an SCM tool, it would probably be better to put the virtual envrionment in another directory so it will not be included in your SCM repository.

Putting the virtual envrionment inside your repository is generally unnecessary as answered here. Python has handy tools like pip to save the list of packages, and easily install them in another virtual envronment.

Output virtual environment packages with pip freeze

pip freeze > requirements.txt

Install packages from requirements.txt with pip install

pip install -r requirements.txt

Recommendation

Say you were using git for SCM, the code could be in

/home/jimmy/git/<projectname>

And the virtual envrionment could be located in

/home/jimmy/venv/<projectname>
Community
  • 1
  • 1
paladin235
  • 34
  • 3