带有matplotlib的pyinstaller backend_wxagg和hashlib md5

时间:2016-07-22 19:58:12

标签: python matplotlib pyinstaller

我的一位同事在构建我们正在共同努力的python应用程序时遇到了问题。我们已经能够隔离问题并使用以下代码进行复制:

print "before import"
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
print "after import"

我们都使用Enthought Canopy Python 2.7.6,matplotlib 1.4.2和pyinstaller 3.2在同一台共享计算机(RHEL 6.6)上工作。

这是有趣的开始:

  • 我们都可以通过python test.py从源代码运行它,它的行为完全符合预期。
  • 我可以使用pyinstaller test.py生成一个可执行文件,除了它所抱怨的丢失.so之外,一切运行正常。
  • 如果我的同事尝试pyinstaller test.py,则生成的可执行文件无需投诉,但是当我们尝试运行它时,我们会收到以下错误消息。

错误:

[username@machine test]$ ./test
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type sha224
ERROR:root:code for hash sha256 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type sha256
ERROR:root:code for hash sha384 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type sha384
ERROR:root:code for hash sha512 was not found.
Traceback (most recent call last):
  File "hashlib.py", line 139, in <module>
  File "hashlib.py", line 91, in __get_builtin_constructor
ValueError: unsupported hash type sha512
before import
Traceback (most recent call last):
  File "test.py", line 3, in <module>
  File "/u/username/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PyInstaller-3.2-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "matplotlib/backends/backend_wxagg.py", line 7, in <module>
  File "/u/username/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PyInstaller-3.2-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "matplotlib/figure.py", line 38, in <module>
  File "/u/username/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PyInstaller-3.2-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "matplotlib/colorbar.py", line 36, in <module>
  File "/u/username/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PyInstaller-3.2-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "matplotlib/contour.py", line 27, in <module>
  File "/u/username/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PyInstaller-3.2-py2.7.egg/PyInstaller/loader/pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "matplotlib/texmanager.py", line 49, in <module>
ImportError: cannot import name md5
Failed to execute script test

显然,我们的环境设置方式有所不同,并且pyinstaller没有提到某些东西。我只是想不通它是什么!我们尝试将hashlib和md5都添加为隐藏导入,但无济于事。

1 个答案:

答案 0 :(得分:0)

尝试使用cx_Freeze构建冻结二进制文件时遇到了同样的错误。在尝试了许多绝望的黑客攻击之后,比如修补hashlib.py,我终于通过完全排除hashlib来消除错误消息。

在cx_Freeze中,它看起来像:

…
excludes = ["collections.abc", "tcl", "tk", "OpenGL", "scipy", "hashlib"]

build_options = {
    "packages": packages,
    "includes": includes,
    "include_files": include_files,
    "excludes": excludes, }
…
setup(name=…,
  version=…,
  description=…,
  options=dict(build_exe=build_options,
               install_exe=install_options),
  executables=executables)

我认为pyinstaller还提供排除库的选项。

我现在正在努力解决与冲突的numpy版本相关的其他错误,因此我无法100%确认错误的消失表明问题已解决。