简体   繁体   English

Django + mod_wsgi + apache2:ImportError:未命名模块<project>

[英]Django + mod_wsgi + apache2: ImportError: No module named <project>

I'm trying to get to the bottom of my problem regarding running any "migrate" command on my django project. 我试图深入了解有关在django项目上运行任何“ migrate”命令的问题。 I have a django app deployed in a virtual env and with mod_wsgi and apache2 the app is served properly at www.mysite.com/test/simulatore. 我在虚拟环境中部署了django应用程序,并使用mod_wsgi和apache2在www.mysite.com/test/simulatore上正确提供了该应用程序。 The problem came when I edited the models, so I had to run 当我编辑模型时出现问题,所以我必须运行

python manage.py makemigrations

After some initial troubleshooting I think I have isolated the problem on wsgi.py 经过一些初步的故障排除,我认为我已经在wsgi.py上隔离了问题
If I try (from my virtualenv) to try to run the command 如果我尝试(从我的virtualenv)尝试运行命令

python -i /home/carma/mycarma_test/mycarma/mycarma/wsgi.py

this is the result 这是结果

['/home/carma/mycarma_test/mycarma/mycarma', '/home/carma/mycarma/testenv/lib/python35.zip', '/home/carma/mycarma/testenv/lib/python3.5', '/home/carma/mycarma/testenv/lib/python3.5/plat-x86_64-linux-gnu', '/home/carma/mycarma/testenv/lib/python3.5/lib-dynload', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/home/carma/mycarma/testenv/lib/python3.5/site-packages', '/home/carma/mycarma_test/mycarma/mycarma/..', '/home/carma/mycarma_test', '/home/carma/mycarma_test/mycarma']
Traceback (most recent call last):
  File "/home/carma/mycarma_test/mycarma/mycarma/wsgi.py", line 22, in <module>
    application = get_wsgi_application()
  File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    django.setup(set_prefix=False)
  File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/carma/mycarma/testenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/home/carma/mycarma/testenv/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named '”mycarma'

As you can see the module mycarma (which is the project name) is reported with single quotes and the just the initial double quote 如您所见,模块mycarma(即项目名称)以单引号和只是初始双引号报告

ImportError: No module named '”mycarma'

This tells me (I think) there is a configuration issue somewhere that is passing a wrong parameter, but I can't find where. 这告诉我(我认为)某个地方传递了错误的参数,但我找不到位置的配置问题。 Here are my settings: 这是我的设置:

Directory structure 目录结构

mycarma_test
└── mycarma
├── manage.py
├── mycarma
│   ├── development_settings.py
│   ├── __init__.py
│   ├── settings.py
│   ├── test_settings.py
│   ├── urls.py
│   └── wsgi.py
├── requirements
│   ├── common.txt
│   ├── dev.txt
│   ├── prod.txt
│   └── test.txt
├── simulatore
│   ├── admin.py
│   ├── apps.py
│   ├── __init__.py
│   ├── migrations
│   │   └── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── templates
    ├── base.html
    ├── registration
    │   └── login.html
    └── simulatore
        └── index.html

File wsgi in mycarma/mycarma 在mycarma / mycarma中归档wsgi

import os
import sys

from django.core.wsgi import get_wsgi_application

DJANGO_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
sys.path.append(DJANGO_PATH)
sys.path.append('/home/carma/mycarma_test')
sys.path.append('/home/carma/mycarma_test/mycarma')
print(sys.path)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mycarma.settings")

application = get_wsgi_application()

Please note I added the two append and the print in order to test/troubleshoot. 请注意,我添加了两个附录和打印件以进行测试/疑难解答。 But also without them no luck. 但也没有他们就没有运气。 settings.py settings.py

ROOT_URLCONF = 'mycarma.urls'
STATIC_URL = '/static/'
STATIC_ROOT = '/home/carma/mycarma/static'

Apache2 conf file Apache2 conf文件

        <Directory /home/carma/mycarma/static>
            Require all granted
    </Directory>

    WSGIDaemonProcess pydaemon-1 processes=1 threads=5 python-path=/home/carma/mycarma/ python-home=/home/carma/mycarma/mycarmaenv
    WSGIDaemonProcess pydaemon-2 processes=1 threads=5 python-path=/home/carma/mycarma_test/mycarma/ python-home=/home/carma/mycarma/testenv

    WSGIScriptAlias /simulatore /home/carma/mycarma/mycarma/wsgi.py

    <Location /simulatore>
            WSGIProcessGroup pydaemon-1
            WSGIApplicationGroup %{GLOBAL}
    </Location>
    <Directory /home/carma/mycarma/mycarma>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

    WSGIScriptAlias /test /home/carma/mycarma_test/mycarma/mycarma/wsgi.py

    <Location /test>
            WSGIProcessGroup pydaemon-2
            WSGIApplicationGroup %{GLOBAL}
    </Location>
    <Directory /home/carma/mycarma_test/mycarma/mycarma>
            <Files wsgi.py>
                    Require all granted
            </Files>
    </Directory>

Thanks. 谢谢。

EDIT: problem found In the dev bin/activate script the 编辑:发现问题在dev bin / activate脚本中

DJANGO_SETTINGS_MODULE=”carma.test_settings”

used some weird double quotes. 用一些奇怪的双引号。 Modified and everything si working. 修改,一切正常。

I am pretty sure that is because you have that extra double quote in your INSTALLED_APPS django config. 我很确定那是因为您在INSTALLED_APPS django配置中有多余的双引号。 This is happening when django bootstraps and tries to load all your apps and it can't locate it. 当Django引导并尝试加载所有应用程序而找不到它时,就会发生这种情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache virtualenv和mod_wsgi:ImportError:没有名为&#39;django&#39;的模块 - Apache virtualenv and mod_wsgi : ImportError : No module named 'django' Django Python mod_wsgi:ImportError:没有名为“ django”的模块 - Django Python mod_wsgi: ImportError: No module named 'django' Ubuntu-Python-Apache2-Mod_WSGI-Django:没有名为/ TypeError / TemplateSyntaxError /&#39;str&#39;对象的模块不可调用 - Ubuntu - Python - Apache2 - Mod_WSGI - Django: No module named / TypeError / TemplateSyntaxError / 'str' object is not callable 使用mod_wsgi在apache2上投放django时出错:没有名为设置的模块 - error serving django on apache2 with mod_wsgi: No module named settings Django mod_wsgi:ImportError:没有名为“ home”的模块 - Django mod_wsgi: ImportError: No module named 'home' ImportError:没有名为appName.settings Django 1.8 + Apache + mod_wsgi的模块 - ImportError: No module named appName.settings django 1.8 + Apache + mod_wsgi 500 内部服务器错误 mod_wsgi apache &quot;importerror: No Module named &#39;django&#39; - 500 internal server error mod_wsgi apache "importerror: No Module named 'django' Django + mod_wsgi + apache: ImportError at / No module named djproj.urls - Django + mod_wsgi + apache: ImportError at / No module named djproj.urls mod_wsgi:ImportError:没有名为&#39;encodings&#39;的模块 - mod_wsgi: ImportError: No module named 'encodings' Django/mod_wsgi/Apache - mod_wsgi 没有使用为它编译的 Python 版本 - “ModuleNotFoundError: No module named 'math'” - Django/mod_wsgi/Apache - mod_wsgi is not using the Python version it was compiled for - “ModuleNotFoundError: No module named 'math' ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM