在Ubuntu-16.04上安装了xampp。 XAMPP根安装位置:/opt/lampp
Python无法导入SSL模块
的Python 2.7.12 Django的1.11 XAMPP 30年5月6日
的wsgi.py设置: ```蟒
import os
import sys
import site
site.addsitedir('/opt/lampp/htdocs/dpcm/dpcm/lib/python2.7/site-packages')
sys.path.insert(0, '/opt/lampp/htdocs/dpcm')
sys.path.insert(1, '/opt/lampp/htdocs/dpcm/dpcm1')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dpcm1.settings")
os.environ.setdefault("PYTHON_EGG_CACHE", "/opt/lampp/htdocs/dpcm/.python-eggs")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# if import ssl module, it will occur an error.
import ssl
```
/opt/lampp/apache2/conf/httpd.conf内容:
Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"
<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /dpcm/ /opt/lampp/htdocs/dpcm/dpcm1/wsgi.py
#WSGIDaemonProcess /dpcm/ python-path=/opt/lampp/htdocs/dpcm:/opt/lampp/htdocs/dpcm/dpcm/lib/python2.7/site-packages
#WSGIProcessGroup /dpcm/
WSGIPythonPath /opt/lampp/htdocs/dpcm
WSGIPythonHome /opt/lampp/htdocs/dpcm/dpcm/
<Directory /opt/lampp/htdocs/dpcm/dpcm1>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Alias /static/ /opt/lampp/htdocs/dpcm/static/
<Directory /opt/lampp/htdocs/dpcm/static>
Order allow,deny
Allow from all
</Directory>
如果导入ssl模块处于非活动模式,则可以成功导入ssl模块。 但如果wsgi.py或其他Django项目文件中添加“导入SSL”,有会报告错误消息:
[Thu Jun 01 10:54:13.272126 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] mod_wsgi (pid=5430): Target WSGI script '/opt/lampp/htdocs/dpcm/dpcm1/wsgi.py' cannot be loaded as Python module.
[Thu Jun 01 10:54:13.272176 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] mod_wsgi (pid=5430): Exception occurred processing WSGI script '/opt/lampp/htdocs/dpcm/dpcm1/wsgi.py'.
[Thu Jun 01 10:54:13.272207 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] Traceback (most recent call last):
[Thu Jun 01 10:54:13.272230 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] File "/opt/lampp/htdocs/dpcm/dpcm1/wsgi.py", line 33, in <module>
[Thu Jun 01 10:54:13.272308 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] import ssl
[Thu Jun 01 10:54:13.272320 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] File "/usr/lib/python2.7/ssl.py", line 97, in <module>
[Thu Jun 01 10:54:13.276754 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] import _ssl # if we can't import it, let the error propagate
[Thu Jun 01 10:54:13.276826 2017] [wsgi:error] [pid 5430] [client 10.0.2.15:41534] ImportError: /opt/lampp/lib/libssl.so.1.0.0: version `OPENSSL_1.0.1' not found (required by /opt/lampp/htdocs/dpcm/dpcm/lib/python2.7/lib-dynload/_ssl.x86_64-linux-gnu.so)
正常,它的。所以链接到/usr/lib
,但它在/opt/lampp/lib
发现, 所以我认为这是env变量问题。在shell脚本 添加以下代码:lampp
LD_LIBRARY_PATH='/usr/lib'
export LD_LIBRARY_PATH
和注释代码
# if test "$(osguess)" = "macosx"
# then
# # Thanks to drosenbe! - oswald [3sep10]
# if test -z $DYLD_LIBRARY_PATH
# then
# export DYLD_LIBRARY_PATH="$LIBRARY_PATH"
# else
# export DYLD_LIBRARY_PATH="$LIBRARY_PATH:$DYLD_LIBRARY_PATH"
# fi
# else
# # Thanks to drosenbe! - oswald [3sep10]
# if test -z $LD_LIBRARY_PATH
# then
# export LD_LIBRARY_PATH="$LIBRARY_PATH"
# else
# export LD_LIBRARY_PATH="$LIBRARY_PATH:$LD_LIBRARY_PATH"
# fi
# fi
这是无用的,没有任何人有同样的问题吗?
建议您阅读http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html,了解如何使用Python虚拟环境设置mod_wsgi的正确方法。你不应该使用''python-path''。尽管如此,这与您的SSL问题无关。 –