Python:当试图编译以解决缺少模块'队列'时?

时间:2017-01-12 01:20:19

标签: python-3.x python-import pyinstaller importerror cx-freeze

同时pyinstallercxfreeze我得到错误

C:\Users\asdasda\Desktop\dist>test.exe
Traceback (most recent call last):
  File "site-packages\requests\packages\__init__.py", line 27, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\packages\urllib3\__init__.py", line 8, in <module
>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\packages\urllib3\connectionpool.py", line 28, in
<module>
  File "site-packages\requests\packages\urllib3\packages\six.py", line 203, in l
oad_module
  File "site-packages\requests\packages\urllib3\packages\six.py", line 115, in _
resolve
  File "site-packages\requests\packages\urllib3\packages\six.py", line 82, in _i
mport_module
ImportError: No module named 'queue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\__init__.py", line 63, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\utils.py", line 24, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\_internal_utils.py", line 11, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\compat.py", line 11, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\requests\packages\__init__.py", line 29, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\urllib3\__init__.py", line 8, in <module>
  File "c:\python34\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",
 line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\urllib3\connectionpool.py", line 28, in <module>
  File "site-packages\urllib3\packages\six.py", line 203, in load_module
  File "site-packages\urllib3\packages\six.py", line 115, in _resolve
  File "site-packages\urllib3\packages\six.py", line 82, in _import_module
ImportError: No module named 'queue'
Failed to execute script test

我尝试编译几个月前编译的完全相同的脚本(它工作时间)但现在我收到的错误让我觉得它是python版本错误,所以我从 3.4.4 切换到 3.5.2 ,但这没有帮助。

我还尝试了pyinstallercxfreeze的不同版本,但都给了我同样的错误。

请帮我解决这个问题。在此先感谢。

2 个答案:

答案 0 :(得分:1)

cxfreeze似乎不支持最新版本requests。通过降级到v2.11.1

为我修复了此错误

pip install requests==2.11.1

答案 1 :(得分:0)

有时未检测到导入。我对队列模块有同样的问题。 将queue模块添加到.spec文件中的隐藏导入为我解决了问题(PyInstaller):

a = Analysis(..., 
             hiddenimports=['queue'],
             ...)