python2.7.3 problem:no module name _ssl

本文章參考與:http://www.webtop.com.au/blog/compiling-python-with-ssl-support-fedora-10-2009020237。

當我"修"好yum之後就開始修python的ssl問題。我的電腦有python的多個版本。在python2.6.6中import
ssl沒錯誤提示,在python2.7.3中import ssl則有no module name _ssl的錯誤提示。

下面是我引用上面地址的文章幷,針對我的問題所在加上註解。

==================================================

I came across this recently, having always thought
that this was part of Python.  When I installed a vanilla Fedora 10
installation, shock horror, I got this error in python!

> python
Python 2.6.1 (r261:67515, Feb 6 2009, 06:29:15)
[GCC 4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Python-2.6.1/lib/python2.6/ssl.py", line 60, in <module>
    import _ssl             # if we can‘t import it, let the error propagate
ImportError: No module named _ssl
>>> import httplib.HTTPSConnection
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named HTTPSConnection
>>>

No SSL? Unheard of! Quickly check to see if you have
OpenSSL installed.





>
yum list installed | grep ssl
openssl.i686                             
0.9.8g-12.fc10              
installed

So the first thing I did was install the development
packages.  Normally they are required when you are compiling your own
installation of python.





>
yum install openssl-devel
Loaded
plugins: refresh-packagekit
fedora                                                  
| 2.8 kB     00:00
updates                                                 
| 2.3 kB     00:00
updates/primary_db                                      
| 2.5 MB     00:03
Setting
up Install Process
Parsing
package install arguments
Resolving
Dependencies
-->
Running transaction check
--->
Package openssl-devel.i386 0:0.9.8g-12.fc10 set to be updated
-->
Processing Dependency: krb5-devel for package: openssl-devel
-->
Running transaction check
--->
Package krb5-devel.i386 0:1.6.3-16.fc10 set to be updated
-->
Processing Dependency: keyutils-libs-devel for package: krb5-devel
-->
Processing Dependency: libselinux-devel for package: krb5-devel
-->
Processing Dependency: e2fsprogs-devel for package: krb5-devel
-->
Running transaction check
--->
Package e2fsprogs-devel.i386 0:1.41.4-1.fc10 set to be updated
-->
Processing Dependency: e2fsprogs-libs = 1.41.4-1.fc10 for package:
e2fsprogs-devel
-->
Processing Dependency: device-mapper-devel >= 1.02.02-3 for package:
e2fsprogs-devel
--->
Package libselinux-devel.i386 0:2.0.73-1.fc10 set to be updated
-->
Processing Dependency: libsepol-devel >= 2.0.32-1 for package:
libselinux-devel
--->
Package keyutils-libs-devel.i386 0:1.2-3.fc9 set to be updated
-->
Running transaction check
--->
Package device-mapper-devel.i386 0:1.02.27-7.fc10 set to be updated
-->
Processing Dependency: e2fsprogs-libs = 1.41.3-2.fc10 for package:
e2fsprogs
--->
Package libsepol-devel.i386 0:2.0.33-1.fc10 set to be updated
--->
Package e2fsprogs-libs.i386 0:1.41.4-1.fc10 set to be updated
-->
Running transaction check
--->
Package e2fsprogs.i386 0:1.41.4-1.fc10 set to be updated
-->
Finished Dependency Resolution

Dependencies
Resolved

================================================================================
 Package                  
Arch      
Version              
Repository     Size
================================================================================
Installing:
 openssl-devel            
i386      
0.9.8g-12.fc10       
updates       1.9 M
Updating:
 e2fsprogs                
i386      
1.41.4-1.fc10        
updates       738 k
 e2fsprogs-libs           
i386      
1.41.4-1.fc10        
updates       151 k
Installing
for dependencies:
 device-mapper-devel      
i386      
1.02.27-7.fc10       
updates        49 k
 e2fsprogs-devel          
i386      
1.41.4-1.fc10        
updates       683 k
 keyutils-libs-devel      
i386      
1.2-3.fc9            
fedora         27 k
 krb5-devel               
i386      
1.6.3-16.fc10        
fedora        1.1 M
 libselinux-devel         
i386      
2.0.73-1.fc10        
fedora        117 k
 libsepol-devel           
i386      
2.0.33-1.fc10        
fedora         60 k

Transaction
Summary
================================================================================
Install     
7 Package(s)
Update      
2 Package(s)
Remove      
0 Package(s)

Total
download size: 4.8 M
Is
this ok [y/N]: y
Downloading
Packages:
(1/9):
keyutils-libs-devel-1.2-3.fc9.i386.rpm           
|  27 kB     00:00
(2/9):
device-mapper-devel-1.02.27-7.fc10.i386.rpm      
|  49 kB     00:00
(3/9):
libsepol-devel-2.0.33-1.fc10.i386.rpm            
|  60 kB     00:00
(4/9):
libselinux-devel-2.0.73-1.fc10.i386.rpm          
| 117 kB     00:00
(5/9):
e2fsprogs-libs-1.41.4-1.fc10.i386.rpm            
| 151 kB     00:00
(6/9):
e2fsprogs-devel-1.41.4-1.fc10.i386.rpm           
| 683 kB     00:01
(7/9):
e2fsprogs-1.41.4-1.fc10.i386.rpm                 
| 738 kB     00:01
(8/9):
krb5-devel-1.6.3-16.fc10.i386.rpm                
| 1.1 MB     00:01
(9/9):
openssl-devel-0.9.8g-12.fc10.i386.rpm            
| 1.9 MB     00:02
--------------------------------------------------------------------------------
Total                                          
570 kB/s | 4.8 MB     00:08
==============================
Entering rpm code ===============================
Running
rpm_check_debug
Running
Transaction Test
Finished
Transaction Test
Transaction
Test Succeeded
Running
Transaction
 
Installing     :
keyutils-libs-devel                                    
1/11
 
Installing     :
device-mapper-devel                                    
2/11
 
Installing     :
libsepol-devel                                         
3/11
 
Updating       :
e2fsprogs-libs                                         
4/11
 
Installing     :
e2fsprogs-devel                                        
5/11
 
Installing     :
libselinux-devel                                       
6/11
 
Installing     :
krb5-devel                                             
7/11
 
Updating       :
e2fsprogs                                              
8/11
 
Installing     :
openssl-devel                                          
9/11
 
Cleanup        :
e2fsprogs-libs                                        
10/11
 
Cleanup        :
e2fsprogs                                             
11/11
===============================
Leaving rpm code ===============================

Installed:
 
openssl-devel.i386 0:0.9.8g-12.fc10

Dependency
Installed:
 
device-mapper-devel.i386 0:1.02.27-7.fc10
 
e2fsprogs-devel.i386 0:1.41.4-1.fc10
 
keyutils-libs-devel.i386 0:1.2-3.fc9
 
krb5-devel.i386 0:1.6.3-16.fc10
 
libselinux-devel.i386 0:2.0.73-1.fc10
 
libsepol-devel.i386 0:2.0.33-1.fc10

Updated:
 
e2fsprogs.i386 0:1.41.4-1.fc10      
e2fsprogs-libs.i386 0:1.41.4-1.fc10

Complete!

Jeepers, a lot for just installing one package! 
But it serves it purpose.





>
yum list installed | grep ssl
openssl.i686                             
0.9.8g-12.fc10              
installed
openssl-devel.i386                       
0.9.8g-12.fc10              
installed

Now I had to modify the file Modules/Setup.dist in
the Python source (mine was located in /usr/local/src/Python-2.6.1). 
Change the following lines (highlighted in red).





>
vi Modules/Setup.dist
 ######這裡Modules/Setup.dist是在你python源碼包裡面的

...

206
# CSV file helper
207
#_csv _csv.c
208
209
# Socket module helper for socket(2)
210
_socket
socketmodule.c#######################這裡和下面橙色部分,在文件中是被注釋的。
211
212
# Socket module helper for SSL support; you must comment out the other
213
# socket line above, and possibly edit the SSL variable:
214
#SSL=/usr/local/ssl
215
_ssl _ssl.c \
216    
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
217    
-L$(SSL)/lib -lssl -lcrypto
218
219
# The crypt module is now disabled by default because it breaks builds
220
# on many systems (where -lcrypt is needed), e.g. Linux (I believe).
221
#
222
# First, look at Setup.config; configure may have set this for you.
223
224
#crypt cryptmodule.c # -lcrypt  # crypt(3); needs -lcrypt on some
systems

Unfortunately, I had to remake the python
installation.  But this should be painless.  Remember, I like to
point to the specific prefix location; you may not.  It should be much
faster second time (or third time...) round.





>
.configure
--prefix=/usr/local/Python-2.6.1===================把python安裝到指定目錄

>
make

>
make install

Check that python now has ssl.





>
python
Python
2.6.1 (r261:67515, Feb 27 2009, 02:54:13)
[GCC
4.3.2 20081105 (Red Hat 4.3.2-7)] on linux2
Type
"help", "copyright", "credits" or "license" for more information.
>>>
import ssl
>>>

No more error!  Now we have SSL support in
Python.

Thanks for the following posts from Grig Gheorghiu and Patrick Altman for their help.

===============================================================

雖然解決了這個ssl的問題,但是運行goagent後,會出現https網頁的CA錯誤提示。這個問題改天解決了再發表上來。

时间: 2024-08-01 16:02:36

python2.7.3 problem:no module name _ssl的相关文章

ImportError: No module named _ssl

编译安装python 2.7后无法导入ssl包 解决办法: 下载地址:http://www.openssl.org/source/openssl-1.0.2a.tar.gz 安装openssl: #tar -xzvf openssl-1.0.2a.tar.gz #./config --prefix=/usr/local --openssldir=/usr/local/openssl #make && make install 重新编译python #vi Python-2.7.9/setu

python3编译安装no module named _ssl

使用源码编译安装python3.6.7以后用pip 安装库, 出现如下问题 Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection import ssl提示: no module named _ssl 解决方法: 在编译时添加对ssl的支持 修改源码中Module文件夹下Setup和Setup.list文件,取消对Socket module helper for

python3报错No module named _ssl

问题:在python使用过程中,发现报错No module named _ssl,但是系统已经安装opensll,于是开始了解决问题之旅原因:python3支持openssl版本最低为1.0.2,而系统比较老,自带的openssl版本为1.0.2参考 https://www.jianshu.com/p/3ec24f563b81 安装新版openssl 下载 https://www.openssl.org/source/ 安装 mkdir /usr/local/openssl tar xf ope

python3.7 ImportError: No module named _ssl 解决方法

笔者在 centos6.5 安装 python3.7 碰到此问题,安装好以后,执行 python3.7 命令行,import ssl 出现错误 ImportError: No module named _ssl . 该错误表现在 pip install 时会报 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 在网上找了很多资料,经过验

安装zlib的过程(Compression requires the (missing) zlib module)(Python2.6升级为2.7出现的问题)

觉得有必要把解决问题的过程写下来 1,因为要安装flask,所以安装pip,所以安装setuptools,所以安装zlib.(具体过程http://www.cnblogs.com/aiyr/p/7260838.html 这个链接中有安装zlib,zlib-devel,耐心找找) 2,之后通过 #rpm -qa | grep zlib查看 发现zlib已经安装成功,可是在安装setuptools的时候还是报错 这不坑爹么. 3,于是去stackoverflow(百度都百烂了都没百出来),直接关键字

ImportError: No module named &amp;#39;ConfigParser&amp;#39;

Resolve Method: I found the problem. I had manually installed a newer version of python (version 3.2 but the version installed through packages is 2.7) and I just redirected /usr/bin/python to python3.2. Apparently in 3.2 some syntax used in /usr/bin

(转)输入pipt提示:AttributeError: &#39;module&#39; object has no attribute &#39;HTTPSConnection&#39;

文章转自:http://write.blog.csdn.net/postedit/51725016 1.测试 [[email protected] ~]# python Python 2.7.8 (default, Jun 17 2016, 01:25:39) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2Type "help", "copyright", "credits" or "

[Webpack 2] Import a non-ES6 module with Webpack

When you have a dependency that does not export itself properly, you can use the exports-loader to force it to export the pieces of the file that you need. Install: npm i -D exports-loader Add exports-loader to the module you want: module: { loaders:

CentOS6.5上配置Python2.7+OpenCV2.4.7

本文讲述在Linux上使用配置Python调用OpenCV的开发环境 环境:CentOS 6.5 +Python2.7.8+OpenCV2.4.7 0.安装OpenCV环境要求(Installation in Linux) OpenCV.org的要求: GCC 4.4.x or later() CMake 2.8.7 or higher Git(如果直接下载了源码,这个没必要) GTK+2.x or higher, including headers (libgtk2.0-dev) pkg-co