How to import _ssl in python 2.7.6?

*爱你&永不变心* 提交于 2019-12-05 11:38:17

I fixed the problem finally! The _ssl module is a built-in module for python, but it requires openssl installed on your system.

Change to root user first! 1.Install openssl and libssl-dev. If on debian OS

apt-get install openssl
apt-get install libssl-dev

2.Recompile python

cd Python2.7.6
./configure
make && make install

But actually, I fix the problem in this way! 1.Install openssl I download a package from the Internet, which is openssl-1.0.2d.tar.gz

tar zxvf openssl-1.0.2d.tar.gz
cd openssl-1.0.2d
./config -fPIC   //configuration:create path independent libssl.a
make && make install

2.Recompile python2.7, and make it support ssl module

tar xvf Python-2.7.6.tar
cd Python-2.7.6
vim Modules/Setup.dist 

find the following line and uncomment it.(use /ssl+Enter to quickly locate these lines in vim)

# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib -lssl -lcrypto

and then config and make, make install

./configure --enable-shared //--enable-shared option means to generate dynamic library libpython2.7.so.1.0
make && make install

Our project depends on libpython2.7.so.1.0. Now I can "import ssl" or "import _ssl" successfully in my python script or python interpreter with the new libpython2.7.so.1.0.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!