无法导入设置'myproject.settings'(是否在sys.path上?):没有名为pinax的模块

时间:2012-02-19 20:49:19

标签: python django pinax

我正在尝试使用pinax处理WebFaction并遇到很多问题......

[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1] mod_wsgi (pid=22796): Exception occurred processing WSGI script '/home/pawesome/webapps/qtsocial/myproject.wsgi'.
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/core/handlers/wsgi.py", line 250, in __call__
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]     self.load_middleware()
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/core/handlers/base.py", line 39, in load_middleware
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/utils/functional.py", line 276, in __getattr__
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]     self._setup()
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/conf/__init__.py", line 42, in _setup
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]     self._wrapped = Settings(settings_module)
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/conf/__init__.py", line 89, in __init__
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Sun Feb 19 20:01:20 2012] [error] [client 127.0.0.1] ImportError: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named pinax

wsgi:

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
application = WSGIHandler()

wsgi与myproject位于同一个文件夹中,而settings.py肯定在myproject中。那是什么给出了什么?

编辑:

好的,所以我从这里和webfaction那里得到了建议,而wsgi现在看起来像这样......

import os
import sys
from site import addsitedir
from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
sys.path.append('/home/pawesome/webapps/qtsocial/myproject')
sys.path.append('/home/pawesome/webapps/qtsocial')

addsitedir('/home/pawesome/envs/pinax072/lib/python2.6/site-packages')
application = WSGIHandler()

我认为这解决了一些问题,但并非一切......现在我得到了......

[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1] mod_wsgi (pid=15572): Exception occurred processing WSGI script '/home/pawesome/webapps/qtsocial/myproject.wsgi'.
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/core/handlers/wsgi.py", line 250, in __call__
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1]     self.load_middleware()
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1]   File "/home/pawesome/webapps/qtsocial/lib/python2.6/django/core/handlers/base.py", line 47, in load_middleware
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1]     raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Sun Feb 19 20:00:28 2012] [error] [client 127.0.0.1] ImproperlyConfigured: Error importing middleware django_openid.consumer: "No module named voting_extras"

再次感谢大家...... WebFaction的人们最近放弃并告诉我来到这里,即使我已经有了lol

7 个答案:

答案 0 :(得分:16)

在终端中,cd进入包含settings.py的目录,然后运行

python settings.py

您可能会收到一个容易修复的导入错误(输入错误或语法错误)。

答案 1 :(得分:11)

您是否曾尝试将该文件夹明确添加到PYTHONPATH?此外,您可能需要添加两者项目文件夹和父项目文件夹。使用项目路径将这些行添加到wsgi文件中:

sys.path.append('/explicit/path/to/myproject')
sys.path.append('/explicit/path/to')

P.S。在application = WSGIHandler()行之前执行此操作。

更新:根据this,新错误似乎有相同的原因。请仔细检查“voting_extras”应用程序的位置,以及PYTHONPATH中是否存在其父文件夹。

答案 2 :(得分:8)

我认为你需要将你的东西添加到PYTHONPATH中。我添加了我的项目,这是virtualenv。 以下是每个项目wsgi的样子。

import sys
import site
import os

envpath = '/development/myproject/env/lib/python2.7/site-packages'

# we add currently directory to path and change to it
pwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(pwd)
sys.path = [pwd] + sys.path

# Append paths
site.addsitedir(envpath)

# now start django
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
application = WSGIHandler()

答案 3 :(得分:3)

有2个问题,

  1. virtualenv应该在〜/ apache2 / bin / start中加载这些行,

    WORKON_HOME=/home/pawesome/envs/pinax072/ . $WORKON_HOME/bin/activate

  2. 您应该使用pinax提供的wsgi文件,而不是我们的安装程序提供的文件,因为pinax有一些需要的自定义路径代码,

    #WSGIScriptAlias / /home/pawesome/webapps/qtsocial/myproject.wsgi WSGIScriptAlias / /home/pawesome/webapps/qtsocial/myproject/deploy/pinax.wsgi

答案 4 :(得分:0)

根据此https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/#using-a-virtualenv,只需在Apache config或您的站点配置(VirtualHost指令之外)中添加指向您的站点包和python site-packages目录的路径

WSGIPythonPath /path/to/mysite.com:/path/to/your/venv/lib/python2.X/site-packages

对我来说,它是:

WSGIPythonPath /var/www/djtest:/usr/local/lib/python2.7/site-packages

答案 5 :(得分:0)

我遇到过类似的问题。在我的情况下,我有一个顶级配置文件夹,其中找到了一般的 settings.py 文件。在 myproject 文件夹中,我有第二个设置,我尝试导入 config.settings 文件。

在我的情况下,问题是python正在查找 myproject.config 文件夹而不是顶级配置

    # project structure
    config/
        settings.py
        constans.py
    myproject/
        config/
            constants.py
        settings.py
        manage.py
        urls.py
  

错误:导入错误:无法导入设置' myproject.settings' (是   它在sys.path上?):没有名为settings的模块

解决方案:我删除/移动了 myproject / config 文件夹。

答案 6 :(得分:-1)

与Pycharm。我关闭了#34;添加内容根源到PYTHONATH"和#34;将源根添加到PYTHONATH"。它有效。