virtualenv 和 Django 目录结构

virtualenv and Django directories structure

我试图在 windows 中使用 virutalenv,但有些奇怪的地方我几乎不了解目录结构。

当您创建一个新的虚拟环境时,它会为您创建以下结构:

C:\Projects\djang_venv\
   Include\
   Lib\
   pip-selfcheck.json
   Scripts\
   tcl\

如果我想在我的 django 项目上工作,我应该把我的项目放在哪里,在 django_vent 目录中?

C:\Projects\djang_venv\
   django_site\
   Include\
   Lib\
   pip-selfcheck.json
   Scripts\
   tcl\

看起来不对,好像这里有什么东西很乱。

创建虚拟环境时我应该把我的应用程序放在哪里?

发现已经有人问了 same question

实际上 one of answers(不是被接受的)是一个非常翔实和清晰的(将在我的结论中包括他的回答)

这是我在 Python 中对虚拟环境世界所做的研究中了解到的:

  1. First of all, it's a matter of opinion. But it is important to note that the experience of the people should be considered, because it is possible to know which method is more appropriate to choose, since the guys with experience understood which method was not good over time.

  2. If you want to stick with virtualenv, one of the solutions keep your directories structure pretty clean outside, Projects directory will stay organized. Put all the virtual environments into one folder, and name each of them after the project you are working on:

c:\projects\virtualenvs\
   django_site\  <-- Virtual environment for Django project
   flast_site\   <-- Virtual environment for Flask project
c:\projects\django_site\  <-- Django project
c:\projects\flask_site\   <-- Flask project

But it's a bit messy with the source command:

cd /django_site
source ../virtualenvs/django_site/bin/activate
  1. To get the most organized environment, without any headache about the order of the virtual environments directories, there is a wrapper for virtualenv called (surprisingly) virtualenvwrapper. All the virtual environments are stored away from you in your HOME_USER directory, for me it's c:\users\my_user\.virtualenvs. And you get great shortcuts by the package, like mkvirtualenv which creating for you a virtual environment no matter where are you in the file system, then you can switch between the virtual environments with the shortcut workon, Some examples:
$ mkvirtualenv flask_site
New python executable in c:\users\usr\.virtualenvs\flask_site\Scripts\python.exe
Installing setuptools, pip, wheel...done.

(flask_site)$ workon
flask_site

(flask_site)$ mkvirtualenv django_site
New python executable in C:\Users\Emilman\.virtualenvs\django_site\Scripts\python.exe
Installing setuptools, pip, wheel...

(django_site)$ workon
django_site
flask_site

(django_site)$ workon flask_site
(flask_site)$

实际上在检查了所有选项后,我选择了virtualenvwrapperPython.

虚拟环境世界的绝佳解决方案