升級Python2.7致使使用pip等命令安裝模塊失敗

1.urllib2.URLError: <urlopen error unknown url type: https>

python 出現'module' object has no attribute 'HTTPSHandler' 錯誤,是由於你編譯python的時候沒有把ssl模塊編譯進去,從新編譯安裝python,並把ssl模塊包含進去就能夠了

cd python源碼目錄/Modules
vi Setup.dst
找到

# 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 python

而後從新make便可 curl

2.安裝openssl錯誤

錯誤以下: socket

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
md5 - x86_64 . s : Assembler messages :
md5 - x86_64 . s : 41 : Error : 0xd76aa478 out range of signed 32bit displacement
md5 - x86_64 . s : 50 : Error : 0xe8c7b756 out range of signed 32bit displacement
md5 - x86_64 . s : 68 : Error : 0xc1bdceee out range of signed 32bit displacement
md5 - x86_64 . s : 77 : Error : 0xf57c0faf out range of signed 32bit displacement
md5 - x86_64 . s : 95 : Error : 0xa8304613 out range of signed 32bit displacement
md5 - x86_64 . s : 104 : Error : 0xfd469501 out range of signed 32bit displacement
md5 - x86_64 . s : 122 : Error : 0x8b44f7af out range of signed 32bit displacement
md5 - x86_64 . s : 131 : Error : 0xffff5bb1 out range of signed 32bit displacement
md5 - x86_64 . s : 140 : Error : 0x895cd7be out range of signed 32bit displacement
md5 - x86_64 . s : 158 : Error : 0xfd987193 out range of signed 32bit displacement
md5 - x86_64 . s : 167 : Error : 0xa679438e out range of signed 32bit displacement
md5 - x86_64 . s : 187 : Error : 0xf61e2562 out range of signed 32bit displacement
md5 - x86_64 . s : 196 : Error : 0xc040b340 out range of signed 32bit displacement
md5 - x86_64 . s : 214 : Error : 0xe9b6c7aa out range of signed 32bit displacement
md5 - x86_64 . s : 223 : Error : 0xd62f105d out range of signed 32bit displacement
md5 - x86_64 . s : 241 : Error : 0xd8a1e681 out range of signed 32bit displacement
md5 - x86_64 . s : 250 : Error : 0xe7d3fbc8 out range of signed 32bit displacement
md5 - x86_64 . s : 268 : Error : 0xc33707d6 out range of signed 32bit displacement
md5 - x86_64 . s : 277 : Error : 0xf4d50d87 out range of signed 32bit displacement
md5 - x86_64 . s : 295 : Error : 0xa9e3e905 out range of signed 32bit displacement
md5 - x86_64 . s : 304 : Error : 0xfcefa3f8 out range of signed 32bit displacement
md5 - x86_64 . s : 322 : Error : 0x8d2a4c8a out range of signed 32bit displacement
md5 - x86_64 . s : 332 : Error : 0xfffa3942 out range of signed 32bit displacement
md5 - x86_64 . s : 340 : Error : 0x8771f681 out range of signed 32bit displacement
md5 - x86_64 . s : 356 : Error : 0xfde5380c out range of signed 32bit displacement
md5 - x86_64 . s : 364 : Error : 0xa4beea44 out range of signed 32bit displacement
md5 - x86_64 . s : 380 : Error : 0xf6bb4b60 out range of signed 32bit displacement
md5 - x86_64 . s : 388 : Error : 0xbebfbc70 out range of signed 32bit displacement
md5 - x86_64 . s : 404 : Error : 0xeaa127fa out range of signed 32bit displacement
md5 - x86_64 . s : 412 : Error : 0xd4ef3085 out range of signed 32bit displacement
md5 - x86_64 . s : 428 : Error : 0xd9d4d039 out range of signed 32bit displacement
md5 - x86_64 . s : 436 : Error : 0xe6db99e5 out range of signed 32bit displacement
md5 - x86_64 . s : 452 : Error : 0xc4ac5665 out range of signed 32bit displacement
md5 - x86_64 . s : 463 : Error : 0xf4292244 out range of signed 32bit displacement
md5 - x86_64 . s : 481 : Error : 0xab9423a7 out range of signed 32bit displacement
md5 - x86_64 . s : 490 : Error : 0xfc93a039 out range of signed 32bit displacement
md5 - x86_64 . s : 508 : Error : 0x8f0ccc92 out range of signed 32bit displacement
md5 - x86_64 . s : 517 : Error : 0xffeff47d out range of signed 32bit displacement
md5 - x86_64 . s : 526 : Error : 0x85845dd1 out range of signed 32bit displacement
md5 - x86_64 . s : 544 : Error : 0xfe2ce6e0 out range of signed 32bit displacement
md5 - x86_64 . s : 553 : Error : 0xa3014314 out range of signed 32bit displacement
md5 - x86_64 . s : 571 : Error : 0xf7537e82 out range of signed 32bit displacement
md5 - x86_64 . s : 580 : Error : 0xbd3af235 out range of signed 32bit displacement
md5 - x86_64 . s : 598 : Error : 0xeb86d391 out range of signed 32bit displacement
make [ 2 ] : * * * [ md5 - x86_64 . o ] Error 1
make [ 2 ] : Leaving directory ` / software / script / openssl - 0.9.8g / crypto / md5 '
make[1]: *** [subdirs] Error 1
make[1]: Leaving directory `/software/script/openssl-0.9.8g/crypto'
make : * * * [ build_crypto ] Error 1

坑爹的也談不上有什麼解法,這裏我編譯的是openssl-0.9.8g,死活編不過,後到openssl資料庫去翻了會,想也沒想換了個版本openssl-0.9.8n,順利編過 網站

3.安裝pip

報錯以下: ui

1
2
3
4
5
# pip
Traceback ( most recent call last ) :
   File "/usr/bin/pip" , line 5 , in < module >
     from pkg_resources import load_entry_point
ImportError : No module named pkg_resources

其實發生這個問題是由於:雖然你已經把Python升級到了2.7版本,可是pip仍然是原來的,版本,仍然在原來python的site-package裏面 url

CentOS5環境下,默認是python2.4,site-package在 spa

1
/ usr / lib / python2 . 4 / site - packages /

不少模塊都被安裝在這裏。直接打pip,仍是使用的原來的pip。因此咱們的思路就是:應該在新的Python中安裝pip,這樣纔不會報錯。 ip

這個問題遇到的人不少,可是解決的太少了,網上都是抄來抄去,都解決不了問題。最後仍是在一外個國人的網站上找到了解決方案: md5

1
2
# curl -O http://python-distribute.org/distribute_setup.py
# /usr/local/pyton2.7/bin/python distribute_setup.py

使用新版本的python來運行這個腳本,這個會自動安裝出來一個easy_install,而後使用這個新的easy_install來安裝pip就能夠了! ssl

1
2
3
# /usr/local/python/bin/easy_install pip
# /usr/local/python/bin/pip -V
pip 1.4.1 from / usr / local / python / lib / python2 . 7 / site - packages / pip - 1.4.1 - py2 . 7.egg ( python 2.7 )

安裝生成的全部二進制文件,都是在你的PYTHON_HOME/bin/,由於個人是安裝在/usr/local/python/,因此命令都在這裏,之後再調用pip要使用絕對路徑,或者作連接!

2.7的模塊是在如下目錄

1
/ usr / local / python / lib / python2 . 7 / site - packages /
相關文章
相關標籤/搜索