运行python文件时出现以下错误:
Traceback (most recent call last):
File "MySimulation.py", line 14, in <module>
from random import *
File "/usr/local/lib/python2.6/random.py", line 48, in <module>
from binascii import hexlify as _hexlify
ImportError: No such file or directory
有解决方案吗?
答案 0 :(得分:2)
来自help(binascii)
。
Help on built-in module binascii:
NAME
binascii - Conversion between binary data and ASCII
FILE
(built-in)
CLASSES
exceptions.Exception(exceptions.BaseException)
Error
Incomplete
class Error(exceptions.Exception)
| Method resolution order:
| Error
| exceptions.Exception
| exceptions.BaseException
| __builtin__.object
|
| Data descriptors defined here:
|
| __weakref__
binascii
是内置模块。您的Python库似乎安装在/usr/local/lib
中。所以,我猜你自己建了它。您确定,它成功构建了binascii
模块吗?那可能是错误。
答案 1 :(得分:0)
如果您从源代码编译Python,则可以创建一个没有binascii
模块的可用Python。我怀疑构建Python时的输出是这样的:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _tkinter bsddb185
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_ctypes _curses _curses_panel
_hashlib _multiprocessing _sqlite3
_ssl binascii bz2
dbm gdbm readline
zlib
您可能还会看到/usr/bin/ld: cannot find -lz
。
问题在于binascii
取决于zlib
。您需要确保链接器找到zlib
:
答案 2 :(得分:-3)
安装binascii
。如果已安装,请确保PYTHONPATH
包含其安装位置。