Django not running: ModuleNotFoundError: No module named 'encodings'
Django not running: ModuleNotFoundError: No module named 'encodings'
我在新的 Ubuntu 17.10 服务器上安装了 django 网站。它基于 python3。当我 运行 网站处于开发模式时使用
它工作正常
python manage.py runserver
但是当我尝试通过 port 80
中的 apache2 网络服务器配置它时,通过编辑默认配置文件在 apache 中添加 wsgi,如图所示..
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/usr/mygpsproject/gps_restapi/gps_restapi>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess gps_restapi python-path=/home/usr/mygpsproject/gps_restapi/ python-home=/home/usr/mygpsproject/venv/bin/
WSGIProcessGroup gps_restapi
WSGIScriptAlias / /home/usr/mygpsproject/gps_restapi/gps_restapi/wsgi.py
</VirtualHost>
但站点无法正常工作。当我检查 apache 错误日志发现这个错误时...
[Sat Apr 14 16:16:09.201739 2018] [core:notice] [pid 5089:tid 140258267696064] AH00051: child pid 7500 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f906c390bc0 (most recent call first):
我找不到这个编码模块是什么。它在开发模式下运行良好。所以 python 肯定不会丢失任何库。
我的配置可能有什么问题。
而不是:
python-home=/home/usr/mygpsproject/venv/bin/
你应该使用:
python-home=/home/usr/mygpsproject/venv
查看有关使用虚拟环境的文档。您应该指向 sys.prefix
给出的虚拟环境的根目录,而不是 bin
目录。
还要确保虚拟环境是从与 mod_wsgi 编译的相同 Python 版本创建的。
最后,根据所使用的 Linux 发行版,您也不应将代码放在个人主目录下,因为主目录的权限可能会导致运行代码的用户如下Apache 无法访问主目录。
我在新的 Ubuntu 17.10 服务器上安装了 django 网站。它基于 python3。当我 运行 网站处于开发模式时使用
它工作正常python manage.py runserver
但是当我尝试通过 port 80
中的 apache2 网络服务器配置它时,通过编辑默认配置文件在 apache 中添加 wsgi,如图所示..
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/usr/mygpsproject/gps_restapi/gps_restapi>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess gps_restapi python-path=/home/usr/mygpsproject/gps_restapi/ python-home=/home/usr/mygpsproject/venv/bin/
WSGIProcessGroup gps_restapi
WSGIScriptAlias / /home/usr/mygpsproject/gps_restapi/gps_restapi/wsgi.py
</VirtualHost>
但站点无法正常工作。当我检查 apache 错误日志发现这个错误时...
[Sat Apr 14 16:16:09.201739 2018] [core:notice] [pid 5089:tid 140258267696064] AH00051: child pid 7500 exit signal Aborted (6), possible coredump in /etc/apache2
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f906c390bc0 (most recent call first):
我找不到这个编码模块是什么。它在开发模式下运行良好。所以 python 肯定不会丢失任何库。
我的配置可能有什么问题。
而不是:
python-home=/home/usr/mygpsproject/venv/bin/
你应该使用:
python-home=/home/usr/mygpsproject/venv
查看有关使用虚拟环境的文档。您应该指向 sys.prefix
给出的虚拟环境的根目录,而不是 bin
目录。
还要确保虚拟环境是从与 mod_wsgi 编译的相同 Python 版本创建的。
最后,根据所使用的 Linux 发行版,您也不应将代码放在个人主目录下,因为主目录的权限可能会导致运行代码的用户如下Apache 无法访问主目录。