【发布时间】:2012-12-19 18:02:55
【问题描述】:
当我尝试这个时,我遇到了这个错误:
来源 ./env/bin/activate
sudo python manage.py syncdb
错误:没有名为 south 的模块
我在激活虚拟环境后安装了 south,使用 pip install south(以及 django)。
settings.py 中已安装的应用:
INSTALLED_APPS = (
'south',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
可能是什么问题?
更新: 尝试在没有 sudo 的情况下进行同步时出现此错误。也许它与“南方”问题有关:
(env)andrius@ubuntu:~/djcode/myproject$ python manage.py syncdb
Syncing...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/andrius/env/local/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 90, in handle_noargs
syncdb.Command().execute(**options)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/home/andrius/env/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/home/andrius/env/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/andrius/env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "/home/andrius/env/local/lib/python2.7/site-packages/psycopg2-2.4.6-py2.7-linux-x86_64.egg/psycopg2/__init__.py", line 178, in connect
return _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL: Peer authentication failed for user "django"
我使用这些命令为数据库创建了数据库和用户:
template1=# create database finance;
CREATE DATABASE
template1=# grant all privileges on database finance to django;
ERROR: role "django" does not exist
template1=# create user django with password 'mydb123';
CREATE ROLE
template1=# grant all privileges on database finance to django;
GRANT
template1=# \q
settings.py 中我的数据库设置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'finance', # Or path to database file if using sqlite3.
'USER': 'django', # Not used with sqlite3.
'PASSWORD': 'mydb123', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
【问题讨论】:
-
尝试将 south 放在已安装应用程序的末尾:现在您已经在系统范围内安装了 South,您需要配置 Django 才能使用它。这样做很简单;只需编辑您的 settings.py 并将 'south' 添加到 INSTALLED_APPS 的末尾。 (south.readthedocs.org/en/0.7.6/…)
-
激活你的 virtualenv,启动 python 并尝试从交互式 shell 中“import south”。成功了吗?
-
其实我先把它放在安装应用的末尾。虽然它给出了同样的错误。我认为使用南路径应该没问题,因为 django 与南在同一目录中,并且 django 应用程序不会出现此错误。
-
@DanielEriksson 是的,在交互式 shell 中有效。
-
所以不明白为什么在交互式外壳中它似乎看到南模块时会出现此错误...
标签: python django virtualenv django-south