0

我正在尝试使用disqus_export.py“django-disqus”中的命令将我的评论从django.contrib.commentsdisqus 导出。

当我disqus_export.py在我的外部项目文件夹中使用时(在哪里manage.py),我得到了回报:

Traceback (most recent call last):
  File "C:\Python27\Lib\site-packages\disqus\management\commands\disqus_export.p
y", line 5, in <module>
    from django.contrib import comments
  File "C:\Python27\lib\site-packages\django\contrib\comments\__init__.py", line
 4, in <module>
    from django.contrib.comments.models import Comment
  File "C:\Python27\lib\site-packages\django\contrib\comments\models.py", line 1
, in <module>
    from django.contrib.auth.models import User
  File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 5, in
 <module>
    from django.db import models
  File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
    self._setup()
  File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _set
up
    raise ImportError("Settings cannot be imported, because environment variable
 %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.

根据另一个类似问题的响应,“检查这个:python manage.pyshell then import syssys.path项目目录在那个路径上吗?退出。输入常规的 python shell python。然后import syssys.path。项目目录在那个路径上吗?”

我这样做了,发现我的项目目录是由第一次调用返回的,但不是后者。但是,给出此指示的评论者没有说明下一步该做什么,因为 OP 明白他必须从那里做什么。

我假设我必须将我的项目目录添加到后者sys.path,但我不知道如何,所以我希望这里有人可以帮助我。

4

1 回答 1

2

sys.path只是一个列表。以下是您所期望的:

sys.path.append('/path/to/project')

或者,您可以将PYTHONPATH环境变量设置为您的项目目录(或编辑它以包含它,如果它已经存在)。

于 2013-05-13T15:09:25.547 回答