简体   繁体   English

无法运行pyinstaller创建的exe文件

[英]Can't run exe file which is created by pyinstaller

I use Pycharm to write the .py source code, it works fine when I use "Run" in Pycharm. 我使用Pycharm编写.py源代码,当我在Pycharm中使用“运行”时,它可以正常工作。 After I finishing writing the source code, I want to use Pyinstaller to pack the code to the executable file, the packing process works fine and the .exe file is created. 完成源代码的编写后,我想使用Pyinstaller将代码打包到可执行文件中,打包过程可以正常工作并创建.exe文件。 But when I double-click the executable file, there is no any reaction. 但是当我双击可执行文件时,没有任何反应。 Don't know what's wrong, please help me. 不知道怎么了,请帮帮我。 Pyinstaller created a warning report in txt file, but I don't think that's the main reason, I attached it at the bottom anyway. Pyinstaller在txt文件中创建了一个警告报告,但是我不认为这是主要原因,无论如何我还是将其附加在底部。

    (venv) D:\Dropbox\Project\Pycharm Projects\biaobai>pyinstaller -F -w -i aixin.ico main.py
1405 INFO: PyInstaller: 3.3.1
1411 INFO: Python: 3.7.0
1413 INFO: Platform: Windows-10-10.0.17134-SP0
1418 INFO: wrote D:\Dropbox\Project\Pycharm Projects\biaobai\main.spec
1431 INFO: UPX is not available.
1448 INFO: Extending PYTHONPATH with paths
['D:\\Dropbox\\Project\\Pycharm Projects\\biaobai',
 'D:\\Dropbox\\Project\\Pycharm Projects\\biaobai']
1449 INFO: checking Analysis
1449 INFO: Building Analysis because out00-Analysis.toc is non existent
1450 INFO: Initializing module dependency graph...
1455 INFO: Initializing module graph hooks...
1458 INFO: Analyzing base_library.zip ...
6290 INFO: running Analysis out00-Analysis.toc
6321 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python.exe
8194 INFO: Caching module hooks...
8206 INFO: Analyzing D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
9513 INFO: Loading module hooks...
9513 INFO: Loading module hook "hook-encodings.py"...
9628 INFO: Loading module hook "hook-PIL.Image.py"...
10335 INFO: Processing pre-find module path hook   distutils
10591 INFO: Loading module hook "hook-PIL.py"...
10607 INFO: Excluding import 'PySide'
10609 INFO:   Removing import of PySide from module PIL.ImageQt
10611 INFO: Import to be excluded not found: 'FixTk'
10612 INFO: Excluding import 'tkinter'
10614 INFO:   Removing import of tkinter from module PIL.ImageTk
10615 INFO: Excluding import 'PyQt4'
10618 INFO:   Removing import of PyQt4 from module PIL.ImageQt
10619 INFO: Excluding import 'PyQt5'
10620 INFO:   Removing import of PyQt5 from module PIL.ImageQt
10621 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
10651 INFO: Import to be excluded not found: 'FixTk'
10651 INFO: Excluding import 'tkinter'
10652 INFO: Loading module hook "hook-pydoc.py"...
10657 INFO: Loading module hook "hook-xml.py"...
11028 INFO: Loading module hook "hook-_tkinter.py"...
11438 INFO: checking Tree
11438 INFO: Building Tree because out00-Tree.toc is non existent
11439 INFO: Building Tree out00-Tree.toc
11549 INFO: checking Tree
11550 INFO: Building Tree because out01-Tree.toc is non existent
11550 INFO: Building Tree out01-Tree.toc
11566 INFO: Loading module hook "hook-distutils.py"...
11609 INFO: Looking for ctypes DLLs
11609 INFO: Analyzing run-time hooks ...
11613 INFO: Including run-time hook 'pyi_rth__tkinter.py'
11624 INFO: Looking for dynamic libraries
13929 INFO: Looking for eggs
13929 INFO: Using Python library D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python37.dll
13930 INFO: Found binding redirects:
[]
13934 INFO: Warnings written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\warnmain.txt
14026 INFO: Graph cross-reference written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\xref-main.html
14105 INFO: checking PYZ
14105 INFO: Building PYZ because out00-PYZ.toc is non existent
14105 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz
15080 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz completed successfully.
15095 INFO: checking PKG
15095 INFO: Building PKG because out00-PKG.toc is non existent
15096 INFO: Building PKG (CArchive) out00-PKG.pkg
18477 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18528 INFO: Bootloader D:\Dropbox\Project\Pycharm Projects\biaobai\venv\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
18529 INFO: checking EXE
18529 INFO: Building EXE because out00-EXE.toc is non existent
18530 INFO: Building EXE from out00-EXE.toc
18555 INFO: SRCPATH [('aixin.ico', None)]
18555 INFO: Updating icons from ['aixin.ico'] to C:\Users\ADMINI~1\AppData\Local\Temp\tmp14uu9lyu
18556 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
18556 INFO: Writing RT_ICON 1 resource with 28840 bytes
18566 INFO: Appending archive to EXE D:\Dropbox\Project\Pycharm Projects\biaobai\dist\main.exe
18591 INFO: Building EXE from out00-EXE.toc completed successfully.

warnmain.txt : warnmain.txt:

missing module named resource - imported by posix, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named posix - imported by os, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _posixsubprocess - imported by subprocess, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named org - imported by pickle, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named readline - imported by cmd, code, pdb, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _winreg - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named 'java.lang' - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named termios - imported by tty, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, getpass
missing module named grp - imported by shutil, tarfile, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, netrc, getpass
missing module named 'org.python' - imported by copy, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax
missing module named cffi - imported by PIL.Image, PIL.PyAccess, PIL.ImageTk
missing module named Tkinter - imported by PIL.ImageTk
missing module named olefile - imported by PIL.FpxImagePlugin, PIL.MicImagePlugin
missing module named UserDict - imported by PIL.PdfParser
missing module named 'PySide.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt4.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt5.QtCore' - imported by PIL.ImageQt
missing module named numpy - imported by PIL.ImageFilter
missing module named pathlib2 - imported by PIL.Image
missing module named __builtin__ - imported by PIL.Image

What has happened is, Pyinstaller haven't been able to find the paths of some modules you have used in your script. 发生的是,Pyinstaller未能找到您在脚本中使用的某些模块的路径。 To Resolve the issue, the simplest thing you could do is extending the path. 要解决此问题,最简单的方法是扩展路径。 You can run this in the pycharm terminal to add these paths into specs file. 您可以在pycharm终端中运行此命令,以将这些路径添加到specs文件中。 Or you could edit the specs file itself. 或者,您可以编辑specs文件本身。

pyi-makespec --paths=/path/to/thisdir \
             --paths=/path/to/otherdir myscript.py

Include all the other places that the script might be searching for imports.These paths will be added to the sys.path during the analysis. 包括脚本可能正在搜索导入的所有其他位置。这些路径将在分析期间添加到sys.path中。

If this didn't work for you, try hidden imports, extending the package path and adding runtime hooks as shown in here . 如果这不是为你工作,试图隐藏的进口,扩大包路径和增加运行时间挂钩,如图这里

I tried to pack the executable file by "pyinstaller -F main.py" instead of using "pyinstaller -F -w main.py". 我尝试通过“ pyinstaller -F main.py”打包可执行文件,而不是使用“ pyinstaller -F -w main.py”打包。 This makes me be able to run the window application through CMD, and then I got the following error: 这使我能够通过CMD运行窗口应用程序,然后出现以下错误:

Fatal Python error: Py_Initialize: Unable to get the locale encoding 致命的Python错误:Py_Initialize:无法获取区域设置编码

zipimport.ZipImportError: can't find module 'encodings' Current zipimport.ZipImportError:找不到模块“编码”当前

thread 0x00003d20 (most recent call first): 线程0x00003d20(最新呼叫优先):

By searching the above error message, I think I get the answer: [ zipimport.ZipImportError: can't find module 'encodings' The conclusion should be: Pyinstaller 3.3.1 doesn't support Python 3.7 . 通过搜索以上错误消息,我想我得到了答案:[ zipimport.ZipImportError:找不到模块'encodings'结论应该是: Pyinstaller 3.3.1不支持Python 3.7

Just now, I tried to change my Python version from 3.7 to 3.6.3, the packing works fine, and finally, I was able to run my .exe file normally. 刚才,我尝试将Python版本从3.7更改为3.6.3,打包工作正常,最后,我能够正常运行.exe文件。

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

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