[英]PyInstaller “failed to execute script” Error
I'm trying to make an exe file with PyInstaller however I'm unable to do so. 我正在尝试使用PyInstaller制作exe文件,但是无法这样做。 The file is built and deposited in the dist folder, however when I try to run it, the the error "Failed to execute script {name}" pops up.
该文件已构建并存放在dist文件夹中,但是当我尝试运行它时,会弹出错误“无法执行脚本{name}”。
Here is the .spec file that I'm using: 这是我正在使用的.spec文件:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['simulator.pyw'],
pathex=['C:\\Simulator'],
binaries=[],
datas=[('bin/**/*.kv', './bin/ui'), ('bin/**/*.xml', './bin/ui')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=True,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='simulator',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False , icon='bin\\ui\\icon.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='simulator')
and this is the output from the console: 这是控制台的输出:
What could be the problem? 可能是什么问题呢?
So you are using Kivy and it logs several errors: 因此,您使用的是Kivy,它会记录几个错误:
picamera - ImportError: No module named picamera
File "c:\python27\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "c:\python27\lib\site-packages\kivy\core\camera\camera_picamera.py", line 18, in <module>
from picamera import PiCamera
gi - ImportError: No module named gi.repository
File "c:\python27\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "c:\python27\lib\site-packages\kivy\core\camera\camera_gi.py", line 10, in <module>
from gi.repository import Gst
opencv - ImportError: No module named cv2
File "c:\python27\lib\site-packages\kivy\core\__init__.py", line 63, in core_select_lib
fromlist=[modulename], level=0)
File "c:\python27\lib\site-packages\kivy\core\camera\camera_opencv.py", line 48, in <module>
import cv2
Did you declare kivy in a requirements.txt file ? 您是否在requirements.txt文件中声明了kivy?
There is also 也有
15333 INFO: Processing pre-safe import module hook win32com
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: No module named win32com
15411 INFO: Processing pre-safe import module hook win32com
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: No module named win32com
which says a library is missing (see ImportError: No module named win32com.client ). 表示缺少库(请参见ImportError:没有名为win32com.client的模块 )。
So, how did you declare the dependencies ? 那么,您如何声明依赖项? We'd need to see your project structure.
我们需要查看您的项目结构。
You can check the full traceback by starting the script via command prompt. 您可以通过在命令提示符下启动脚本来检查完整的回溯。
This can be done by pressing WIN
+ R
and writting cmd
then changing the directory with cd command
until you reach the folder, and then use .\\<softwarename>.exe
to run. 这可以通过按
WIN
+ R
并编写cmd
然后使用cd command
更改目录直到到达文件夹,然后使用.\\<softwarename>.exe
来完成。
For example: 例如:
> cd C:\softwares\test
> pwd
C:\softwares\test
> .\test.exe
From experience, this probably is caused by a ModuleNotFoundError
. 根据经验,这可能是由
ModuleNotFoundError
引起的。 If that's the problem you can add the module name to the hiddenimports
list at the spec. 如果这是问题所在,可以在规范
hiddenimports
模块名称添加到hiddenimports
列表中。
ie: hiddenimports=['pyodbc'],
即:
hiddenimports=['pyodbc'],
The problems seemed to be indeed in Kivy ( https://kivy.org/doc/stable/guide/packaging-windows.html#alternate-installations ). 问题似乎确实在Kivy中( https://kivy.org/doc/stable/guide/packaging-windows.html#alternate-installations )。 I modified the .spec file and the application was built successfully.
我修改了.spec文件,并成功构建了该应用程序。
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['simulator.pyw'],
pathex=['C:\\Python27\\Scripts\\Simulator'],
binaries=[],
datas=[('./bin/ui/dynamic_classes.kv', './bin/ui/'), ('./bin/ui/main_layout.kv', './bin/ui/'), ('./bin/ui/text.xml', './bin/ui/'), ('./bin/ui/treatment_adaptive.kv', './bin/ui/'), ('./bin/ui/treatment_classic.kv', './bin/ui/'), ('./bin/ui/treatment_user.kv', './bin/ui/'), ('./bin/ui/icon.ico', './bin/ui/')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=True,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='simulator',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
clean=True,
console=False, icon='bin\\ui\\icon.ico')
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
Tree('C:\\Python27\\share\\sdl2\\bin'),
Tree('C:\\Python27\\share\\glew\\bin'),
strip=False,
upx=True,
upx_exclude=[],
name='simulator')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.