Python到可执行文件 - 无法导入模块

时间:2015-10-25 21:28:34

标签: python exe

在Win10 x64上运行Python 3.5。尝试了py2exe,PyInstaller和cxfreeze。所有这些都运行并生成.exe。但是没有一个.exes在错误发生后立即关闭所有.exes。所有这些都有警告日志,其中包含大量无法正确导入的必需模块。

PyInstaller:

missing module named time.time - imported by time, http.cookies
...
missing module named urllib.proxy_bypass - imported by urllib, requests.compat 
...

cxfreeze:

Missing modules:

    ? Cookie imported from requests.compat
    ? Image imported from openpyxl.drawing.image
    ? OpenSSL.SSL imported from requests.packages.urllib3.contrib.pyopenssl
    ? StringIO imported from requests.compat, requests.packages.urllib3.packages.six
    ...

PyInstaller还会丢失诸如“api-ms-win-crt-runtime-l1-1-0.dll”之类的依赖性错误。我安装了Visual C ++ 2005-2015并安装了Visual Studio Community 15。

2 个答案:

答案 0 :(得分:0)

PyInstaller 3.0  Python 3.5 on Win10 x64 with Visual Studio Community 15 
works for me. I run pyinstaller --onefile file_script.py
    in windows path i have the folowing
    C:\Python35;
    C:\Python35\Scripts;
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;

答案 1 :(得分:0)

事实证明这是openpyxl的一个问题,它是一个正在导入的模块。

https://bitbucket.org/openpyxl/openpyxl/issues/498/moving-constants-to-a-configuration-file https://bitbucket.org/openpyxl/openpyxl/pull-requests/67/include-constantsjson-as-part-of-the/diff https://bitbucket.org/openpyxl/openpyxl/pull-requests/83/use-__about__py-instead-of-constantsjson/diff

下载存储库的副本,使用上一个URL中所做的更改,然后从中安装openpyxl(使用`pip install -e(openpyxldirectory))可以生成正在运行的.exe