0

在 ubuntu lucid 中,我安装了 python2.7.5 并设置了一个 virtualenv。在终端中我输入 workon envpy275 并使用 pip 从需求文件中安装了这些 sw

python==2.7.5
Django==1.4.3
South==0.7.6
distribute==0.6.28
dj-database-url==0.2.1
django-registration==0.8
numpy==1.4.1
matplotlib==1.2.0
psycopg2==2.4.6
python-memcached==1.48
simplejson==3.0.7
wsgiref==0.1.2

$workon envpy275
(envpy27)me@ubuntu:~/dev/python/django/myapp$ pip install -r requirements.txt

这将这些软件安装到~/.virtualenv/envpy275/lib/python2.7/site-packages.

我的系统已经有Django1.4./home/me/Django-1.4并且我的 .bashrc 文件有

PYTHONPATH=/home/me/Django-1.4
PYTHONPATH=$PYTHONPATH:/home/me/dev/python/django/myapp

因为我的项目设置文件在/home/me/dev/python/django/myapp/mysite directory 我设置 DJANGO_SETTINGS_MODULE 如下

 (envpy27)me@ubuntu:~/dev/python/django/myapp$ export DJANGO_SETTINGS_MODULE='mysite.setings'

然后,在终端,我尝试运行 django 服务器

(envpy27)me@ubuntu:~/dev/python/django/myapp$ python manage.py runserver

这产生了以下警告和错误

/home/me/.virtualenvs/envpy275/lib/python2.7/site-packages/pytz/__init__.py:35: UserWarning: 
Module django was already imported from 
    /home/me/Django-1.4/django/__init__.pyc, but /home/me/.virtualenvs/envpy275/lib/python2.7/site-packages 
is being added to sys.path
 from pkg_resources import resource_stream
  ...
  ...
 file "/home/me/Django-1.4/django/conf/__init__.py", line 95, in __init__
  raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
 ImportError: Could not import settings 'mysite.setings' (Is it on sys.path?): No module named setings
4

1 回答 1

0

您可能在将 DJANGO_SETTINGS_MODULE 设置为 mysite.setings 时出现拼写错误 - 通常这将mysite.settings指向一个文件mysite/settings.py

于 2013-05-20T06:39:32.643 回答