ModuleNotFoundError: No module named 'new' error with django deployment using apache
ModuleNotFoundError: No module named 'new' error with django deployment using apache
使用版本:
Centos 7---django 2.1.7---Apache 2.4.6---Python 3.6
我在尝试访问服务器 url 时遇到此错误:
[wsgi:error] mod_wsgi (pid=9020): Failed to exec Python script file '/home/user/project/new/wsgi.py'.
[wsgi:error] mod_wsgi (pid=9020): Exception occurred processing WSGI script '/home/conner.johnson/ek/new/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/home/user/project/new/wsgi.py", line 19, in <module>
[wsgi:error] application = get_wsgi_application()
[wsgi:error] File "/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] django.setup(set_prefix=False)
[wsgi:error] File "/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[wsgi:error] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
[wsgi:error] self._setup(name)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
[wsgi:error] self._wrapped = Settings(settings_module)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
[wsgi:error] mod = importlib.import_module(self.SETTINGS_MODULE)
[wsgi:error] File "/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[wsgi:error] return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[wsgi:error] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[wsgi:error] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[wsgi:error] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[wsgi:error] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[wsgi:error] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[wsgi:error] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[wsgi:error] ModuleNotFoundError: No module named 'new'
我的文件结构(2 个应用程序,但一个应用程序 'new' 仅包含设置,wsgi.py,urls.py 指向第二个应用程序)
─ home
└── user
└── project
├── app
│ ├── <All Code for Webapp including static dir>
├── env (virtualenv)
├── manage.py
├── new
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── requirements.txt
我的 django.conf 文件似乎是有序的,但也许不是,我取出了 python-home,因为它似乎没有做任何重要的事情
django.conf:
Alias /static /home/user/project/static
<Directory /home/user/project/static>
Require all granted
</Directory>
<Directory /home/user/project/new>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess ek python-path=/home/user/project/new
WSGIProcessGroup ek
WSGIScriptAlias / /home/user/project/new/wsgi.py
TimeOut 600
我的wsgi.py(我没有动过)
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'new.settings')
application = get_wsgi_application()
我试过将它添加到 wsgi.py
import sys
sys.path.append('/home/user/project')
sys.path.append('/home/user/project/new')
但这似乎没有任何作用
我还尝试将 'new' 添加到已安装应用程序下的 settings.py
python 路径变量是正确的并指向 'new' 所在的地方 wsgi.py,我不认为添加 python-home 变量会起作用很多。
我搜索了具有相同答案的其他帖子,但找不到解决方法,有人有任何想法吗?
看起来你应该有 python-path=/home/user/project/
这样你就可以导入 new
.
使用版本:
Centos 7---django 2.1.7---Apache 2.4.6---Python 3.6
我在尝试访问服务器 url 时遇到此错误:
[wsgi:error] mod_wsgi (pid=9020): Failed to exec Python script file '/home/user/project/new/wsgi.py'.
[wsgi:error] mod_wsgi (pid=9020): Exception occurred processing WSGI script '/home/conner.johnson/ek/new/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error] File "/home/user/project/new/wsgi.py", line 19, in <module>
[wsgi:error] application = get_wsgi_application()
[wsgi:error] File "/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] django.setup(set_prefix=False)
[wsgi:error] File "/lib/python3.6/site-packages/django/__init__.py", line 19, in setup
[wsgi:error] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 57, in __getattr__
[wsgi:error] self._setup(name)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 44, in _setup
[wsgi:error] self._wrapped = Settings(settings_module)
[wsgi:error] File "/lib/python3.6/site-packages/django/conf/__init__.py", line 107, in __init__
[wsgi:error] mod = importlib.import_module(self.SETTINGS_MODULE)
[wsgi:error] File "/lib64/python3.6/importlib/__init__.py", line 126, in import_module
[wsgi:error] return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[wsgi:error] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[wsgi:error] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
[wsgi:error] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[wsgi:error] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[wsgi:error] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[wsgi:error] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[wsgi:error] ModuleNotFoundError: No module named 'new'
我的文件结构(2 个应用程序,但一个应用程序 'new' 仅包含设置,wsgi.py,urls.py 指向第二个应用程序)
─ home
└── user
└── project
├── app
│ ├── <All Code for Webapp including static dir>
├── env (virtualenv)
├── manage.py
├── new
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── requirements.txt
我的 django.conf 文件似乎是有序的,但也许不是,我取出了 python-home,因为它似乎没有做任何重要的事情
django.conf:
Alias /static /home/user/project/static
<Directory /home/user/project/static>
Require all granted
</Directory>
<Directory /home/user/project/new>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIApplicationGroup %{GLOBAL}
WSGIDaemonProcess ek python-path=/home/user/project/new
WSGIProcessGroup ek
WSGIScriptAlias / /home/user/project/new/wsgi.py
TimeOut 600
我的wsgi.py(我没有动过)
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'new.settings')
application = get_wsgi_application()
我试过将它添加到 wsgi.py
import sys
sys.path.append('/home/user/project')
sys.path.append('/home/user/project/new')
但这似乎没有任何作用
我还尝试将 'new' 添加到已安装应用程序下的 settings.py
python 路径变量是正确的并指向 'new' 所在的地方 wsgi.py,我不认为添加 python-home 变量会起作用很多。
我搜索了具有相同答案的其他帖子,但找不到解决方法,有人有任何想法吗?
看起来你应该有 python-path=/home/user/project/
这样你就可以导入 new
.