python manage.py syncdb 错误:没有名为 south 的模块。在 Virtualenvwrapper 外部调用 Django 安装。
我在一个使用 virtualenvwrapper
的环境中安装了 Django,并且还安装了 South。不过,当我运行 python manage.py syncdb
时,系统却调用了在 virtualenvwrapper
外部的 Django 安装,这样就找不到 south
了。我该怎么解决这个问题呢?
[~/devground/django_gilgamesh]# pip install south
Downloading/unpacking south
Downloading South-0.8.4-py2.py3-none-any.whl (135kB): 135kB downloaded
Installing collected packages: south
Successfully installed south
Cleaning up...
(django_gilgamesh)sdye@dy-borg.com [~/devground/django_gilgamesh]# python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sdye/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/sdye/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sdye/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/sdye/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/sdye/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/sdye/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/sdye/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/sdye/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/sdye/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named south
补充说明:我在 settings.py 文件中尝试过使用 'south' 和 'South'。下面是 settings.py 文件的内容。补充说明:我用 'south' 替换了 traceback,并重新安装了 south。补充说明2:运行 which django-admin.py
的输出是 /home/sdye/.virtualenvs/django_gilgamesh/bin/django-admin.py
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'p3)1ravw(zzt25-$tj0fd@r8^i1(0b1==tuk5e3ph32k8yjs20'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'django_gilgamesh.urls'
WSGI_APPLICATION = 'django_gilgamesh.wsgi.application'
更新:在命令行测试时,运行 import south
出现了 ImportError: No module named south 的错误。
1 个回答
1
解决了:看起来Python在虚拟环境外面寻找south。当我在关闭虚拟环境后安装south时,迁移就成功了。不过这又引出了另一个问题,我会在新帖子里发出来。
注意:因为我是在虚拟环境中安装的Django,所以本来不应该出现这种情况。
有没有人知道怎么解决这个问题,或者能给个更好的解释,为什么会发生这种情况?