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

落爺英雄遲暮 提交于 2019-11-28 07:02:41

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

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.

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

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

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

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!