Python import random報錯處理辦法


【轉自】http://blog.chinaunix.net/uid-26000296-id-4356738.html

python安裝失敗:make的時候報錯:

/usr/include/tkDecls.h:1542: error: expected ‘)’ before ‘*’ token
/usr/include/tkDecls.h:1639: error: expected declaration specifiers or ‘...’ before ‘Drawable’
/usr/include/tkDecls.h:1674: error: expected ‘)’ before ‘*’ token
/usr/include/tkDecls.h:1679: error: expected ‘)’ before ‘*’ token
/usr/include/tkDecls.h:1710: error: expected specifier-qualifier-list before ‘XColor’

Failed to find the necessary bits to build these modules:
bsddb185 dl imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


Failed to build these modules:
_tkinter binascii zlib

上述錯誤,導致的結果是:

[storm@bs035 rpm]$ python
Python 2.6.6 (r266:84292, Apr 12 2016, 18:51:29)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/random.py", line 48, in <module>
from binascii import hexlify as _hexlify
ImportError: No module named binascii
>>>

解決辦法

python版本不正常導致的。

升級安裝zlib
# wget http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz 
# cd zlib-1.2.8
# ./configure 
# make install

升級安裝sqlite3
# cd ..
# wget http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# tar -zxvf sqlite-autoconf-3080500.tar.gz
# cd sqlite-autoconf-3080500
# ./configure
# make
# make install

# cd ../Python-2.7.3
# make –s
# make && sudo make install

 

MD,之前可能刪過linux自帶的rpm包。

血淋淋的教訓啊,搞這個東東,搞了接近一天(先是一個個找rpm包,然后又按照正常的機器上裝的rpm包重新下了一遍)。。。

感謝原文的分享啊,不然還不知道要糾結多久。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM