ModuleNotFoundError:使用apache部署django时没有名为“new”的模块错误
使用版本: Centos 7--django 2.1.7--Apache2.4.6--Python 3.6 尝试访问服务器的url时出现此错误:ModuleNotFoundError:使用apache部署django时没有名为“new”的模块错误,django,apache,mod-wsgi,Django,Apache,Mod Wsgi,使用版本: Centos 7--django 2.1.7--Apache2.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 scri
[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'
我已尝试将此添加到wsgi.py
import sys
sys.path.append('/home/user/project')
sys.path.append('/home/user/project/new')
但这似乎没有任何作用
我还尝试将“新建”添加到已安装应用程序下的settings.py中
pythonpath变量是正确的,它指向wsgi.py所在的“new”,我认为添加python home变量不会有多大作用
我已经用同样的答案搜索了其他帖子,但找不到解决方法,有人有什么想法吗?看起来你应该有python path=/home/user/project/这样你就可以导入新的了。所以在python path的末尾取下/new?是的,你想能够导入新的.settings,因此,您希望包含new的目录位于python路径上。
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
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'new.settings')
application = get_wsgi_application()
import sys
sys.path.append('/home/user/project')
sys.path.append('/home/user/project/new')