我正在尝试将Django应用程序上的SQLite数据库迁移到MySQL。对于MySQL python连接器的某些问题,我决定在我工作的Debian发行版上升级到python 3.6。
迁移数据库后,我尝试运行该应用程序,但在apache错误日志文件中遇到此错误:
Current thread 0x00007f1488aee780 (most recent call first):
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
我已将其添加到我的httpd.conf中:
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
LoadModule wsgi_module /usr/local/venvs/myapp/lib/python3.6/site-packages/mod_wsgi/server/mod_wsgi-py36.cpython-36m-x86_64-linux-gnu.so
#Django
WSGIDaemonProcess django_myapp python-home=/usr/local/venvs/myapp
WSGIProcessGroup django_myapp
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /var/www/django/django_myapp/wsgi.py
WSGIPassAuthorization On
Alias /static /var/www/django/static
<Directory /var/www/django/static>
Require all granted
</Directory>
<Directory /var/www/django/django_myapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
从error.log文件中:
Apache/2.4.10 (Debian) mod_wsgi/4.6.5 Python/3.6
我已经使用命令
安装了新的python版本 env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.3
。
我已经设置了虚拟环境,并安装了通过pip运行我的应用程序所需的所有软件包。
另外mod_wsgi
是通过pip安装的。