python2.7.3 problem:no module name _ssl,python安装ssl,本文章參考與:htt


本文章參考與: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的錯誤提示。

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

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

Icame across this recently, having always thought that this was part of Python. When Iinstalled a vanilla Fedora 10 installation, shock horror, Igot this error in python!

> python
Python 2.6.1 (r261:67515, Feb6 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 OpenSSLinstalled.

> 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 Ihad 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, Ihad to remake the python installation. But this should be painless. Remember, Ilike 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 fromGrig GheorghiuandPatrick Altmanfor their help.

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

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


python2.7.3 problem:no module name _ssl,布布扣,bubuko.com

python2.7.3 problem:no module name _ssl

评论关闭