使用 django(我已经尝试了许多版本 1.8.7、1.11.X、2.0.1) python3.5 amd wsgi 4.5.24 从源代码编译,确保 Python 路径设置正确/usr/bin/python3.5
我有一个带有多个 wsgi sript 别名的 apache 文件,除了 django 脚本别名之外,所有这些别名都可以工作,它仅在解析 wsgi.py 文件时失败,因为它无法导入 django。所以首先是来自 apache 的错误:
[Tue Jan 02 18:46:32.247088 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] mod_wsgi (pid=2475): Target WSGI script '/var/www/protectionprofiles/protectionprofiles/wsgi.py' cannot be loaded as Python module.
[Tue Jan 02 18:46:32.247260 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] mod_wsgi (pid=2475): Exception occurred processing WSGI script '/var/www/protectionprofiles/protectionprofiles/wsgi.py'.
[Tue Jan 02 18:46:32.247523 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] Traceback (most recent call last):
[Tue Jan 02 18:46:32.247637 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] File "/var/www/protectionprofiles/protectionprofiles/wsgi.py", line 12, in <module>
[Tue Jan 02 18:46:32.247699 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] from django.core.wsgi import get_wsgi_application
[Tue Jan 02 18:46:32.247772 2018] [wsgi:error] [pid 2475:tid 139822294771456] [remote 192.168.254.101:2418] ImportError: No module named 'django'
和我的 Apache 配置:
<VirtualHost *:80>
WSGIScriptAlias /certs /var/www/scripts/CavsCertSearch/CavsCertSearch/certstrip.wsgi
WSGIScriptAlias /testcerts /var/www/scripts/CavsCertSearchTest/CavsCertSearch/certstriptest.wsgi
WSGIScriptAlias /debug /var/www/scripts/debug/debug.wsgi
WSGIDaemonProcess protectionprofiles python-path=/var/www/protectionprofiles
WSGIProcessGroup protectionprofiles
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias /pp /var/www/protectionprofiles/protectionprofiles/wsgi.py process-group=protectionprofiles
<Directory /var/www/protectionprofiles/protectionprofiles>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static/ /var/www/protectionprofiles/static/
<Directory /var/www/protectionprofiles/static>
Require all granted
</Directory>
</VirtualHost>
它只是保护配置文件失败的最后一个脚本别名。 Django 是用 pip3 安装的,这就是我指定版本的方式。我不需要使用虚拟环境,我仍然不真正理解这一点。但是当我在解释器上使用python时,我可以说
import django
它工作正常。任何提示都是关于如何让 django 包在mod_wsgi下运行会有所帮助,感觉我已经遵循了所有教程,但似乎都没有工作。提前谢谢你。
想要添加一些版本信息。 运行以下示例: http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-installation-in-use 产生:
sys.version = '3.5.3 (default, Nov 23 2017, 11:34:05) n[GCC 6.3.0 20170406]'
sys.prefix = '/usr'
sys.path = ['/var/www/protectionprofiles', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']
因此,正如 Graham 帮助我发现的那样,在 python 中有一个本地和全局版本的包管理器。所以我需要做的就是
pip3 uninstall django
sudo -H pip3 install django==1.11.9