I'm trying to make an exe file with PyInstaller however I'm unable to do so. 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.
Here is the .spec file that I'm using:
# -*- 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:
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 ?
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 ).
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.
For example:
> cd C:\softwares\test
> pwd
C:\softwares\test
> .\test.exe
From experience, this probably is caused by a ModuleNotFoundError
. If that's the problem you can add the module name to the hiddenimports
list at the spec.
ie: hiddenimports=['pyodbc'],
The problems seemed to be indeed in Kivy ( https://kivy.org/doc/stable/guide/packaging-windows.html#alternate-installations ). I modified the .spec file and the application was built successfully.
# -*- 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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.