Could not import settings 'myproject.settings' (Is it on sys.path?): No module named pinax
Asked Answered
D

7

11

I'm trying to get pinax working on WebFaction and having so many issues...

[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

The wsgi:

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

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

The wsgi is in the same folder as myproject and settings.py is definitely in myproject. So what gives?

EDIT:

Okay so I took the advice from here as well as from webfaction and the wsgi now looks like this...

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()

I think this has solved something but not everything... now I am getting...

[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"

Thanks again guys... The people at WebFaction have recently given up and told me to come here even though I already had lol

Demonstrator answered 19/2, 2012 at 20:49 Comment(0)
D
3

There were 2 issues,

  1. The virtualenv should be loaded in ~/apache2/bin/start with these lines,

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

  2. You should be using the wsgi file provided by pinax and not the one our installer provides as pinax has some custom path code that is needed,

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

Demonstrator answered 20/2, 2012 at 18:2 Comment(0)
M
20

In your terminal, cd into the directory that contains settings.py, then run

python settings.py

You may get an import error that is easily fixed (typing error, or syntax error).

Mean answered 19/5, 2014 at 20:45 Comment(0)
S
11

Have you tried to add that folder to your PYTHONPATH explicitly? Also, you may need to add both the project folder and the parent one. Add these lines to your wsgi file, using the path of your project:

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

P.S. do that before the application = WSGIHandler()line.

Update: the new error seems to have the same cause, according to this. Please double-check where your "voting_extras" app is, and whether or not its parent folder is present in the PYTHONPATH.

Satchel answered 19/2, 2012 at 21:0 Comment(2)
Okay so I took the advice from here as well as from webfaction and the wsgi now looks like this... 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()Demonstrator
@Demonstrator updated the answer based on some info from webfaction, I hope it helps...Satchel
P
8

I think you need to add your stuff to the PYTHONPATH. I add my project and it's virtualenv. Here is a sample of what your wsgi could look like per project.

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()
Prothallus answered 19/2, 2012 at 21:8 Comment(0)
D
3

There were 2 issues,

  1. The virtualenv should be loaded in ~/apache2/bin/start with these lines,

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

  2. You should be using the wsgi file provided by pinax and not the one our installer provides as pinax has some custom path code that is needed,

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

Demonstrator answered 20/2, 2012 at 18:2 Comment(0)
D
0

According to this https://docs.djangoproject.com/en/1.5/howto/deployment/wsgi/modwsgi/#using-a-virtualenv just add path to your site package and python site-packages directory in Apache config or your site config (outside VirtualHost directive)

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

For me, it was:

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

Detruncate answered 1/3, 2013 at 11:8 Comment(0)
W
0

I've encounter a similar problem. In my case I had a top level config folder, where general settings.py file was located. In myproject folder I had a second settings where I try to import config.settings file.

In my case the problem was that python was looking in myproject.config folder instead of top level config.

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

err: ImportError: Could not import settings 'myproject.settings' (Is it on sys.path?): No module named settings

Solution: I removed/moved the myproject/config folder.

Westlund answered 19/4, 2017 at 16:4 Comment(0)
E
-1

with Pycharm. I closed "Add content roots to PYTHONATH" and "Add source roots to PYTHONATH". It works.

Excel answered 1/4, 2016 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.