嗨这是一个古老的问题,但看到它没有回答。不知道你正试图做什么,但基本上有两种模式可以使用的virtualenv,
- 的发展空间,打造自成体系的环境
- 对于部署,打造自成体系的环境
在第一种情况下,您需要首先使用source venv/bin/activate激活您的virtualenv,因为在部署时,您需要确保为您的网站代码激活了virtualenv。我个人更喜欢以下方法来确保您的路径设置正确。 (我也这样做时,开发添加到我的manage.py,所以我不担心第一激活环境。
修改manage.py
#!/usr/bin/env python
import os.path
# Cater for Virtual env, add to sys.path
pwd = os.path.abspath(os.path.dirname(__file__))
project = os.path.basename(pwd)
new_path = pwd.strip(project)
activate_this = os.path.join(new_path,'venv','bin','activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
这工作,因为我是如何组织我项目,你就必须将其更改为您的目录结构我的项目的构成就像这样:
TopLevelDir
|
|- Project DIR
|- venv
|- requirements
|- deployment configs
什么家当的内容你正在运行的manage.py的顶部?在激活virtualenv时,用于运行Python交互式解释器和manage.py的确切命令是什么? – 2010-08-25 13:08:02