使用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']
答案 0 :(得分:0)
正如格雷厄姆帮助我弄清楚的那样,在python中有一个本地和全球版本的包管理器。所以我需要做的就是
pip3 uninstall django
sudo -H pip3 install django==1.11.9