简体   繁体   English

PyInstaller可执行文件引发ImportError:没有名为请求的模块

[英]PyInstaller executable raises ImportError: no module named requests

I'm having a problem creating a standalone executable using PyInstaller. 我在使用PyInstaller创建独立可执行文件时遇到问题。 Specifically, when I run pyinstaller -F module_name.py, it creates the executable, but the executable fails with ImportError: no module named requests. 具体来说,当我运行pyinstaller -F module_name.py时,它会创建可执行文件,但是该可执行文件会因ImportError失败:没有名为请求的模块。 The module runs fine through the REPL. 该模块可以通过REPL正常运行。 I know there's a few other questions out there with ImportErrors using PyInstaller; 我知道还有其他一些使用PyInstaller的ImportErrors问题。 I've researched them and still can't get it working. 我已经研究了它们,但仍然无法正常工作。

Here's my setup: 这是我的设置:

  • Pycharm 2016.3 on Windows 7 64-bit Windows 7 64位上的Pycharm 2016.3
  • Python 2.7.12 32-bit in a virtual environment 虚拟环境中的Python 2.7.12 32位
  • PyInstaller 3.2 PyInstaller 3.2

This is a brand-new virtual environment, with the absolute minimum that I need to run this program. 这是一个全新的虚拟环境,运行该程序所需的绝对最低资源。 Requests and PyInstaller are both freshly installed from pip, and pip confirms that they're both up-to-date. Requests和PyInstaller都是从pip全新安装的,并且pip确认它们都是最新的。

I've checked my PYTHONPATH, and the path to the virtual environment is in there and correct, and requests is in the virtual environment's site_packages directory. 我已经检查了我的PYTHONPATH,虚拟环境的路径在其中并且正确,请求在虚拟环境的site_packages目录中。 I've tried adding --hiddenimports=requests, no change. 我尝试添加--hiddenimports = requests,没有任何变化。 I hope I'm not missing something obvious, but I'm about out of ideas. 我希望我不会错过任何明显的东西,但是我没有想法。

One thing I have noticed: the warncheck.txt file generated by PyInstaller shows a massive number of missing imports, many of them standard libraries (like re, and functools, and datetime). 我注意到的一件事:PyInstaller生成的warncheck.txt文件显示了大量丢失的导入,其中许多是标准库(例如re,functools和datetime)。 I don't know if this is a symptom of something else wrong. 我不知道这是否是其他错误的征兆。

Any help would be appreciated. 任何帮助,将不胜感激。

The one thing I forgot to try last night was to try a different version of PyInstaller. 昨晚我忘记尝试的一件事是尝试使用其他版本的PyInstaller。 I uninstalled PyInstaller 3.2 and installed PyInstaller 3.1, and the executable now runs perfectly with no problems. 我卸载了PyInstaller 3.2并安装了PyInstaller 3.1,该可执行文件现在可以完美运行,没有任何问题。 I will be reporting the issue to the PyInstaller folks so they can figure out the problem on their end. 我将向PyInstaller人员报告该问题,以便他们最终解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM