autopytoexe:找不到模块请求

2024-07-05 12:42:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python脚本,我想把它转换成.exe,我用auto-py-to-exe来实现这一点。我的文件在一个文件夹中,文件夹中还有程序运行所需的文本文件和图片

我通常填充字段,运行它,然后尝试.exe:module requests not found。请求是我在python脚本中进行的第一次导入

我在硝酸盐(https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/)上看到了这一点:

"ModuleNotFoundError: No module named x / ImportError: No module named x

这意味着未将特定模块(本例中为“x”)添加到包中。我在pandas库和win32api中的包中看到过这种情况;只要您能够识别软件包(例如“x”),就很容易修复

要在UI中解决此问题,请打开“高级”选项卡并找到--hidden导入输入。只需将模块名称粘贴到此输入中,然后重新打包。如果原始错误仍然出现,则表明您的操作不正确

例如,如果缺少pandas.\u libs.tslib,请通过--hidden import将“pandas.\u libs.tslib”添加到输入中。此外,您可以添加多个模块,例如pandas._libs.tslib、win32api。(有关更多信息,请参见输入旁边的问号)。”

然后,我发现了这个问题:Cannot run Python file as .exe file, getting error 'ModuleNotFoundError: No module named 'pandas' '

他似乎在熊猫身上也遇到了同样的错误(引用Nitratine的话:“我在熊猫库和win32api中看到过这种情况”)并遵循了Nitratine的解决方案,并且成功了

他分享了一个截图:https://i.stack.imgur.com/WMpws.png

所以我做了完全相同的事情,我把“请求”放在字段中,然后…“无法执行脚本”

如何解决此错误

编辑:以下是命令的日志:

Running auto-py-to-exe v2.7.5
Building directory: C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a
Provided command: pyinstaller --noconfirm --onedir --windowed --add-data "C:/Hack/ProxyCrawler;ProxyCrawler/" --hidden-import "requests"  "C:/Hack/ProxyCrawler/Script.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --windowed --add-data C:/Hack/ProxyCrawler;ProxyCrawler/ --hidden-import requests C:/Hack/ProxyCrawler/Script.py --distpath C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\application --workpath C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build --specpath C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a

49308 INFO: PyInstaller: 3.6
49321 INFO: Python: 3.7.7
49334 INFO: Platform: Windows-10-10.0.17763-SP0
49343 INFO: wrote C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\Script.spec
49358 INFO: UPX is not available.
49391 INFO: Extending PYTHONPATH with paths
['C:\\Hack\\ProxyCrawler',
 'C:\\Users\\ELVE~1\\AppData\\Local\\Temp\\tmpgj8a1e2a']
49401 INFO: checking Analysis
49406 INFO: Building Analysis because Analysis-00.toc is non existent
49418 INFO: Initializing module dependency graph...
49521 INFO: Caching module graph hooks...
49568 INFO: Analyzing base_library.zip ...
56240 INFO: Processing pre-find module path hook   distutils
56269 INFO: distutils: retargeting to non-venv dir 'c:\\panda3d-1.10.6-x64\\python\\lib'
61992 INFO: Caching module dependency graph...
62249 INFO: running Analysis Analysis-00.toc
62301 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\panda3d-1.10.6-x64\python\python.exe
62521 INFO: Analyzing C:\Hack\ProxyCrawler\Script.py
63303 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
69165 INFO: Processing module hooks...
69170 INFO: Loading module hook "hook-certifi.py"...
69191 INFO: Loading module hook "hook-distutils.py"...
69209 INFO: Loading module hook "hook-encodings.py"...
69456 INFO: Loading module hook "hook-pydoc.py"...
69466 INFO: Loading module hook "hook-sysconfig.py"...
69479 INFO: Loading module hook "hook-xml.py"...
69807 INFO: Loading module hook "hook-_tkinter.py"...
70226 INFO: checking Tree
70233 INFO: Building Tree because Tree-00.toc is non existent
70246 INFO: Building Tree Tree-00.toc
70500 INFO: checking Tree
70507 INFO: Building Tree because Tree-01.toc is non existent
70521 INFO: Building Tree Tree-01.toc
70603 INFO: Looking for ctypes DLLs
70610 INFO: Analyzing run-time hooks ...
70630 INFO: Including run-time hook 'pyi_rth__tkinter.py'
70659 INFO: Including run-time hook 'pyi_rth_certifi.py'
70695 INFO: Looking for dynamic libraries
71326 INFO: Looking for eggs
71334 INFO: Using Python library c:\panda3d-1.10.6-x64\python\python37.dll
71347 INFO: Found binding redirects: 
[]
71362 INFO: Warnings written to C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build\Script\warn-Script.txt
71481 INFO: Graph cross-reference written to C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build\Script\xref-Script.html
71552 INFO: Appending 'datas' from .spec
71570 INFO: checking PYZ
71580 INFO: Building PYZ because PYZ-00.toc is non existent
71586 INFO: Building PYZ (ZlibArchive) C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build\Script\PYZ-00.pyz
72799 INFO: Building PYZ (ZlibArchive) C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build\Script\PYZ-00.pyz completed successfully.
72843 INFO: checking PKG
72851 INFO: Building PKG because PKG-00.toc is non existent
72861 INFO: Building PKG (CArchive) PKG-00.pkg
72927 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
72938 INFO: Bootloader c:\panda3d-1.10.6-x64\python\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
72953 INFO: checking EXE
72963 INFO: Building EXE because EXE-00.toc is non existent
72993 INFO: Building EXE from EXE-00.toc
73024 INFO: Appending archive to EXE C:\Users\ELVE~1\AppData\Local\Temp\tmpgj8a1e2a\build\Script\Script.exe
73219 INFO: Building EXE from EXE-00.toc completed successfully.
73239 INFO: checking COLLECT
73247 INFO: Building COLLECT because COLLECT-00.toc is non existent
73265 INFO: Building COLLECT COLLECT-00.toc
87856 INFO: Building COLLECT COLLECT-00.toc completed successfully.

Moving project to: C:\Users\Elève\output
Complete.

(我是法国人,所以如果你听不懂“Elève”(学生)之类的名字,这很正常)

编辑编号2: Eric Mathieu试图通过评论来帮助我,他提到了应该出现的“build”和“dist”文件夹。我没有得到它们中的任何一个,在遵循教程尝试获得更多帮助时,我发现:

https://datatofish.com/wp-content/uploads/2019/03/004_pyinstaller.png

所以他得到了一个“pycache”文件夹(我不能把这两个放进去,因为否则pycache这个词会变为粗体“^^”),一个“dist”和一个“build”文件夹。我有“pycache”,但“dist”和“build”文件夹都没有……也许这能帮上忙

我谈论的教程在这里:https://datatofish.com/executable-pyinstaller/


Tags: topyinfotreelocalscripthookusers