嗨這是一個古老的問題,但看到它沒有回答。不知道你正試圖做什麼,但基本上有兩種模式可以使用的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