Get Fatal Python错误:找不到模块:没有名为encoding的模块



我正试图让我的Apache Web服务器使用wsgi.py运行我的Django页面。我的虚拟环境位于/var/www/myapp/myapp_root/myapp。当我激活虚拟环境时,我会看到我的用户主目录正在被使用。我尝试了以下wsgi.py更改:

"""
WSGI config for trackx project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os,sys
sys.path.append('/home/myuserid/.local/share/virtualenvs/lib/python3.9/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trackx.settings')
application = get_wsgi_application()

当我尝试启动服务器时,它会给我以下重复错误(一遍又一遍):

Python path configuration:
PYTHONHOME = '/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9'
PYTHONPATH = (not set)
program name = 'python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/local/bin/python3'
sys.base_prefix = '/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9'
sys.base_exec_prefix = '/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9'
sys.executable = '/usr/local/bin/python3'
sys.prefix = '/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9'
sys.exec_prefix = '/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9'
sys.path = [
'/home/my-user/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9/lib64/python38.zip',
'/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9/lib64/python3.8',
'/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9/lib64/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f52bfd07880 (most recent call first):
<no Python frame>

http.conf文件中的WSGI设置如下。。。

WSGIPythonHome /var/www/myapp/myapp_root/venv
WSGIPythonPath /var/www/myapp/myapp_root/venv/lib/python3.9/site-packages
WSGIDaemonProcess myapp python-home=/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/myapp/myapp_root/myapp/wsgi.py
<Directory /var/www/myapp/myapp_root/myapp>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>

任何人遇到这个错误——任何想法都会很棒。已尝试将一些设置更改为我的实际设置。local目录,但这似乎会产生权限错误,然后我仍然会得到相同的重复错误结果。

我发现我的路径在wsgi.py.中不正确

当我添加根目录时,设置文件被正确访问,它成功地加载了wsgi.py。

所以wsgi.py现在看起来像:

import os,sys
sys.path.append('/var/www/myapp/myapp_root')
sys.path.append('/usr/local/lib')
sys.path.append('/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9/site-packages/MySQLdb')
sys.path.append('/home/myuser/.local/share/virtualenvs/myapp-nygxcPTP/lib/python3.9/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myapp.settings')
application = get_wsgi_application()

相关内容

  • 没有找到相关文章

最新更新