在Windows上使用全局包的virtualenv
我安装了最新版本的virtualenv、django-nonrel、djangotoolbox和django_mongodb_engine。这个virtualenv是用-no-site-packages创建的。
我试着按照快速入门的步骤来操作,但在运行syncdb的时候遇到了以下错误:
Traceback (most recent call last):
File "C:\www\environments\mongotest\djangomongo\manage.py", line 11, in <
module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\utils\import
lib.py", line 35, in import_module
__import__(name)
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\commands\syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_
signal
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\core\managem
ent\sql.py", line 5, in <module>
from django.contrib.contenttypes import generic
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\contrib\cont
enttypes\generic.py", line 6, in <module>
from django.db import connection
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\db\__init__.
py", line 77, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\db\utils.py"
, line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python25\lib\site-packages\django-1.2.3-py2.5.egg\django\db\utils.py"
, line 49, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an av
ailable database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named django_mongodb_engine.base
看起来它在尝试使用默认的django安装,而不是我环境中的django-nonrel安装。
我试着添加了set PYTHONPATH=%PYTHONPATH%;C:\path\to\env\Lib\site-packages\django,但没有任何变化。
有没有人知道为什么这里会使用默认的django安装呢?
3 个回答
0
我来分享一下我对这个问题的看法:
如果你在用Eclipse这个软件,可以通过PyDev这个插件来解决这个问题。只需要把新的解释器指向你要用的新项目,就可以搞定了。
1
你试过运行 activate.bat
吗?
另外,我觉得设置 PYTHONPATH 应该可以解决问题,但你需要把新的路径放在最前面,而且这个路径应该指向包含 Django 安装文件的文件夹,而不是指向 Django 本身:
set PYTHONPATH=C:\path\to\env\Lib\site-packages\;%PYTHONPATH%
2
问题出在Windows的文件关联上。我当时想通过“manage.py syncdb”来同步数据库,这个命令用了默认的Windows Python安装。可是如果我用“python manage.py syncdb”,就能使用正确的Python和环境了。