编译二进制文件的Python导入错误?

时间:2015-07-01 14:14:17

标签: python import pyhook

我试图分发一个使用pyHook的python应用程序我使用cx_Freeze来编译二进制文件。原始python项目以.py形式完美运行。但是,来自cx_freeze的已编译二进制文件在给出此Traceback后终止:

    Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pyHook\cpyHook.py", line 18, in swig_impor
t_helper
    fp, pathname, description = imp.find_module('_cpyHook', [dirname(__file__)])

  File "C:\Python34\lib\imp.py", line 297, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_cpyHook'

During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27
    , in <module>
        exec(code, m.__dict__)
      File "WinComLog.py", line 5, in <module>
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_a
    nd_load
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_a
    nd_load_unlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_u
    nlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_b
    ackward_compatible
      File "C:\Python34\lib\site-packages\pyHook\__init__.py", line 1, in <module>
        from .HookManager import *
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_a
    nd_load
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_a
    nd_load_unlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_u
    nlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_b
    ackward_compatible
      File "C:\Python34\lib\site-packages\pyHook\HookManager.py", line 1, in <module
    >
        from . import cpyHook
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2284, in _handle
    _fromlist
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 321, in _call_wi
    th_frames_removed
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_a
    nd_load
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2226, in _find_a
    nd_load_unlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_u
    nlocked
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_b
    ackward_compatible
      File "C:\Python34\lib\site-packages\pyHook\cpyHook.py", line 28, in <module>
        _cpyHook = swig_import_helper()
      File "C:\Python34\lib\site-packages\pyHook\cpyHook.py", line 20, in swig_impor
    t_helper
        import _cpyHook
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2237, in _find_a
    nd_load
      File "c:\python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2224, in _find_a
    nd_load_unlocked
    ImportError: No module named '_cpyHook'

显然,它无法找到_cpyHook,这是PyHook库的一部分。我尝试了很多搜索,但无法找到有关此问题的任何有用信息。如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。

在编译之前,将_cpyHook.pydcpyHook.py文件从"c:\PythonXX\Lib\site-packages\pyHook"复制到"c:\PythonXX\Lib\site-packages",然后进行编译即可。