Pyinstaller: Failed to execute script main

Created on 15 May 2017  路  50Comments  路  Source: pyinstaller/pyinstaller

Windows 7x64 SP1
Python 2.7.13
PyInstaller-3.3.dev0+5b6288b
PySide 1.2.4

import sys
from PySide import QtGui
from PySide import QtCore

app = QtGui.QApplication(sys.argv)
label = QtGui.QLabel("Hello World")
label.show()
app.exec_()
sys.exit()

with

pyinstaller --name Check main.py

compiles (with no errors) a Check.exe that when it runs gives me the

Traceback (most recent call last):
  File "main.py", line 2, in <module>
  File "d:\apps\dev\python\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\PySide\__init__.py", line 41, in <module>
  File "site-packages\PySide\__init__.py", line 11, in _setupQtDirectories
  File "site-packages\PySide\_utils.py", line 95, in get_pyside_dir
  File "site-packages\PySide\_utils.py", line 88, in _get_win32_case_sensitive_name
  File "site-packages\PySide\_utils.py", line 63, in _get_win32_short_name
WindowsError: [Error 2] The system cannot find the file specified.
Failed to execute script main

error.
The Pyside installation directory is

D:\Apps\DEV\PYTHON\Python27\Lib\site-packages\PySide\

Any ideas?
Should I write this path somewhere?

invalid

All 50 comments

I would recommend that you use pyqt because it's better supported.

"Better" support than what?
Not compiling a "hello world" script?
I was hoping for an actual solution to this...

We run tests on PyQt. We don't run tests on PySide. Therefore, it's not surprising that PySide doesn't work, aside from what the README says. You have two options:

  • You can implement support for PySide
  • You can use PyQt5, which is the most likely to work

I was hoping for an actual solution to this...

In case you decide to attempt the first option, what you need to do is implement a runtime hook that monkeypatches that specific function so that it doesn't fail and possibly an additional hook that includes the required directories. Runtime hooks are in PyInstaller/loader/rthooks and Hooks are in PyInstaller/hooks.

You may be surprised by the tone of my response, but I will inform you that PyInstaller is more advanced than any other freezer and even at that, it still requires a LOT of maintenance to support 90% of use cases. Python is simply not a language designed to make freezing easy.

I don't really have any option.
I can't use PyQt for licensing reasons and I don't know how to implement support for PySide, since if I did I wasn't gonna ask for help on this.

You may be surprised by the tone of my response, but I will inform you that PyInstaller is more advanced than any other freezer and even at that, it still requires a LOT of maintenance to support 90% of use cases.

The first alternative that I checked (cx_freeze) could compile that simple script.
My problem is that I'm already using PyInstaller 2.1 for some time now, and I have learn some of its quirks (copying some directories manually when needed for complicated projects) after a lot of experimentation, and its working.
I have to update because of a newer kivy version, but I don't want to start from scratch.

Anyway, are there any resources or suggestions about adding this path to the PyInstaller?

What's the file it's looking for? [print it]

WindowsError: [Error 2] The system cannot find the file specified.
Failed to execute script main

It must be referring to the main.py (the name of the simple script)

Those two messages are completely unrelated. The first is the error message which doesn't show the file. You need to discover it by modifying utils.py to print the file.

The second message comes from PyInstaller: it simply says that PyInstaller could not execute the entry point.

Yes, they are unrelated.
It was looking for the _utils.pyc file inside the PySide directory.
I copied these where it wants them and now we are facing the real problem.

Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py", line 43
, in <module>
ImportError: No module named PyQt4.QtCore
Failed to execute script pyi_rth_qt4plugins

The reason for this is the PySide import that fails

try:
    from PySide.QtCore import QCoreApplication
except ImportError:
    from PyQt4.QtCore import QCoreApplication

and then tries to import PyQt.

try:

from PyInstaller.utils.hooks import collect_submodules
hiddenimports += collect_submodules('PySide')

On another note, your problems may come from the fact that you appear to be using PySide, which has been replaced by PySide2.

Where should I put this?
Trying the .spec file, gives me
NameError: name 'hiddenimports' is not defined

Pyside2 is not replacing PySide just yet
Its still work in progress.

Tried this

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = []
hiddenimports += collect_submodules('PySide')

and

a = Analysis(['main.py'],
             pathex=['C:\\Users\\X\\Desktop\\DEV\\PROJECTS\\4Build\\_Check'],
             binaries=[],
             datas=[],
             hiddenimports=hiddenimports,
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

that did run but gave me the original No module named PyQt4.QtCore error.

Back to search.
@xoviat
I couldn't find a way to add the hiddenimports code you gave me, but, trying to find why it doesn't import PySide I ditch the try/except and followed the errors.
I got this

  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py", line 41, in <module>
  File "d:\apps\dev\python\python27\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 688, in load_module
    module = imp.load_module(fullname, fp, filename, ext_tuple)
ImportError: DLL load failed: The specified procedure could not be found.
Failed to execute script pyi_rth_qt4plugins

When I printed the fullname, fp, filename, ext_tuple and I've got

PySide.QtCore <open file 'D:\\Apps\\DEV\\PROJECTS\\4Build\\_Check\\dist\\Check\\PySide.QtCore.pyd', mode 'rb' at 0x0232C968> D:\Apps\DEV\PROJECTS\4Build\_Check\dist\Check\PySide.QtCore.pyd ('.pyd', 'rb', 3)

which I think it means that it cannot find the PySide.QtCore.pyd file.
The file is there but keeps giving me the same error.
Any ideas?

In the pyimod03_importers.py file (where the error happens) there is this comment:
# Python 2 implementation - TODO drop or improve it. 'imp' module is no longer built-in. and I wonder if this is why The specified procedure could not be found.

Don't waste your time on pyimod03_importers. That error means that PyInstaller is putting in a DLL that works with a different Python version. Try to find where the DLL is that Python uses by default and then compare it to the DLL that PyInstaller has included.

So, any other ideas?
What about the

from PyInstaller.utils.hooks import collect_submodules
hiddenimports += collect_submodules('PySide')

How should I use it?

Note: this is psuedocode for what you should look at:

> import PySide.QtCore
> print(PySide.QtCore.__file__)
> assert open(PySide.QtCore.__file__).read() == open('D:\Apps\DEV\PROJECTS\4Build\_Check\dist\Check\PySide.QtCore.py').read()

How should I use it?

Don't. That was for a different error that you don't have but I thought you did earlier.

IOError: [Errno 22] invalid mode ('r') or filename: 'D:\\Apps\\DEV\\PROJECTS\x04Build\\_Check\\dist\\Check\\PySide.QtCore.py'

It's psuedocode. What you need to do is run the first two lines, find where that file is located, and then compare it to the file in the PyI project.

> import PySide.QtCore
> print(PySide.QtCore.__file__)

run that in the REPL and it will tell you

D:/Apps/DEV/PYTHON/Python27/lib/site-packages/PySide/QtCore.pyd

are the contents of that file the same as the contents of the file in the PyI project?

No there aren't.
I copied the QtCore.pyd and rename it PySide.QtCore.pyd but I still get the same error...

let me look at the c++ and then I'll come back to this later

Thank you.

Using python 2.7.13 and PyInstaller 3.3.dev0+c7a24e5, I was unable to replicate this problem. Below is the directory listing that I have. What is different?

    Directory: C:\Users\User\Downloads\dist\test


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d-----        5/18/2017  10:04 AM                qt4_plugins                                                           
-a----        5/18/2017  10:04 AM          92672 bz2.pyd                                                               
-a----        5/18/2017  10:04 AM           1052 Microsoft.VC90.CRT.manifest                                           
-a----        5/18/2017  10:04 AM         245760 msvcm90.dll                                                           
-a----        5/18/2017  10:04 AM         854160 msvcp90.dll                                                           
-a----        5/18/2017  10:04 AM         642192 msvcr90.dll                                                           
-a----        5/18/2017  10:07 AM              0 out.txt                                                               
-a----        5/18/2017  10:04 AM         141824 pyside-python2.7.dll                                                  
-a----        5/18/2017  10:04 AM        2293760 PySide.QtCore.pyd                                                     
-a----        5/18/2017  10:04 AM        8679424 PySide.QtGui.pyd                                                      
-a----        5/18/2017  10:04 AM         808448 PySide.QtNetwork.pyd                                                  
-a----        5/18/2017  10:04 AM        3407872 python27.dll                                                          
-a----        5/18/2017  10:04 AM        2992640 Qt3Support4.dll                                                       
-a----        5/18/2017  10:04 AM        3251712 QtCore4.dll                                                           
-a----        5/18/2017  10:04 AM       10889728 QtGui4.dll                                                            
-a----        5/18/2017  10:04 AM        1364480 QtNetwork4.dll                                                        
-a----        5/18/2017  10:04 AM         921088 QtOpenGL4.dll                                                         
-a----        5/18/2017  10:04 AM         255488 QtSql4.dll                                                            
-a----        5/18/2017  10:04 AM         353280 QtSvg4.dll                                                            
-a----        5/18/2017  10:04 AM         468992 QtXml4.dll                                                            
-a----        5/18/2017  10:04 AM          11776 select.pyd                                                            
-a----        5/18/2017  10:04 AM         152576 shiboken-python2.7.dll                                                
-a----        5/18/2017  10:04 AM         805692 test.exe                                                              
-a----        5/18/2017  10:04 AM           1012 test.exe.manifest                                                     
-a----        5/18/2017  10:04 AM         692224 unicodedata.pyd                                                       
-a----        5/18/2017  10:04 AM         120832 _ctypes.pyd                                                           
-a----        5/18/2017  10:04 AM        1482240 _hashlib.pyd                                                          


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
d-----        5/18/2017  10:04 AM                accessible                                                            
d-----        5/18/2017  10:04 AM                codecs                                                                
d-----        5/18/2017  10:04 AM                graphicssystems                                                       
d-----        5/18/2017  10:04 AM                iconengines                                                           
d-----        5/18/2017  10:04 AM                imageformats                                                          


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins\accessible


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/18/2017  10:04 AM          45056 qtaccessiblecompatwidgets4.dll                                        
-a----        5/18/2017  10:04 AM         245248 qtaccessiblewidgets4.dll                                              


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins\codecs


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/18/2017  10:04 AM         145920 qcncodecs4.dll                                                        
-a----        5/18/2017  10:04 AM         176128 qjpcodecs4.dll                                                        
-a----        5/18/2017  10:04 AM          81408 qkrcodecs4.dll                                                        
-a----        5/18/2017  10:04 AM         159744 qtwcodecs4.dll                                                        


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins\graphicssystems


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/18/2017  10:04 AM          16896 qglgraphicssystem4.dll                                                
-a----        5/18/2017  10:04 AM          26624 qtracegraphicssystem4.dll                                             


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins\iconengines


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/18/2017  10:04 AM          43520 qsvgicon4.dll                                                         


    Directory: C:\Users\User\Downloads\dist\test\qt4_plugins\imageformats


Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/18/2017  10:04 AM          33280 qgif4.dll                                                             
-a----        5/18/2017  10:04 AM          34816 qico4.dll                                                             
-a----        5/18/2017  10:04 AM         239616 qjpeg4.dll                                                            
-a----        5/18/2017  10:04 AM         279040 qmng4.dll                                                             
-a----        5/18/2017  10:04 AM          26112 qsvg4.dll                                                             
-a----        5/18/2017  10:04 AM          25088 qtga4.dll                                                             
-a----        5/18/2017  10:04 AM         358912 qtiff4.dll                                                            



In the dist directory I have these directories that you don't:
"4Build_Check\dist\Check\adodbapi"
"4Build_Check\dist\Check\Demos"
"4Build_Check\dist\Check\include"
"4Build_Check\dist\Check\isapi"
"4Build_Check\dist\Check\libs"
"4Build_Check\dist\Check\pywin"
"4Build_Check\dist\Check\test"
"4Build_Check\dist\Check\win32com"
"4Build_Check\dist\Check\win32comext"

and these extra files:
"4Build_Check\dist\Check_socket.pyd"
"4Build_Check\dist\Check_ssl.pyd"
"4Build_Check\dist\Check\license.txt"
"4Build_Check\dist\Check\mfc90.dll"
"4Build_Check\dist\Check\mfc90u.dll"
"4Build_Check\dist\Check\mfcm90.dll"
"4Build_Check\dist\Check\mfcm90u.dll"
"4Build_Check\dist\Check\Microsoft.VC90.CRT.manifest"
"4Build_Check\dist\Check\Microsoft.VC90.MFC.manifest"
"4Build_Check\dist\Check\perfmondata.dll"
"4Build_Check\dist\Check\pythoncom27.dll"
"4Build_Check\dist\Check\pythoncomloader27.dll"
"4Build_Check\dist\Check\pythonservice.exe"
"4Build_Check\dist\Check\Pythonwin.exe"
"4Build_Check\dist\Check\PyWin32.chm"
"4Build_Check\dist\Check\pywin32.pth"
"4Build_Check\dist\Check\pywin32.version.txt"
"4Build_Check\dist\Check\pywin32-218-py2.7.egg-info"
"4Build_Check\dist\Check\pywintypes27.dll"
"4Build_Check\dist\Check\scintilla.dll"
"4Build_Check\dist\Check\unicodedata.pyd"
"4Build_Check\dist\Check\win32api.pyd"
"4Build_Check\dist\Check\win32evtlog.pyd"

The contents of the qt4_plugins folders are the same.
I couldn't compare the sizes (I think they are different)
How can I take the print you took? Is it some command I can use in the cmd.exe?

The powershell command is ls -r

actually let me upload my program and you can see whether it works on your computer.

Do you use Windows 7 x64?

And no, I use windows 10

The test.exe runs fine.
Comparing your files with the same mine, shows that all of them are different.
What version of PySide are you using?
Is your Python 32bit?
Is the different windows version enough to justify these differences?

PySide 1.2.4
Windows 10 x64
Python 2.7 x64

Also pypiwin32 is 219.

I think the problem is the Python 2.7 x86
Can you check this?

@xoviat
Any news for the Python 2.7.13 x86 support (in x64 systems)?
Can I help testing this here in some way?

I'll test this sometime soon, but I'm honestly not optimistic that I'll be able to reproduce this issue, and if I cannot reproduce the issue, there is very little chance of me fixing it.

I think that if you install the 32bit version of python in your x64 system, you will have the same problems with PyInstaller.
You can also try a VM.
If you need any testing, tell me.
... and thank you for your time...

I think that if you install the 32bit version of python in your x64 system, you will have the same problems with PyInstaller.

Nope. Everything works fine with Python 2.7.13 x86, as I thought it would.

If you need any testing, tell me.

How about posting the output of the example script using log-level=TRACE.

The contents of the warncheck.txt are

missing module named PyQt4 - imported by d:\apps\dev\python\python27\lib\site-packages\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py
missing module named org - imported by copy
missing module named console - imported by pyreadline.console.ansi
missing module named startup - imported by pyreadline.keysyms.common, pyreadline.keysyms.keysyms
missing module named System - imported by pyreadline.clipboard.ironpython_clipboard, pyreadline.keysyms.ironpython_keysyms, pyreadline.console.ironpython_console, pyreadline.rlmain
missing module named _scproxy - imported by urllib
missing module named EasyDialogs - imported by getpass
missing module named termios - imported by getpass
missing module named pwd - imported by posixpath, getpass
missing module named SOCKS - imported by ftplib
missing module named rourl2path - imported by urllib
missing module named IronPythonConsole - imported by pyreadline.console.ironpython_console
missing module named clr - imported by pyreadline.clipboard.ironpython_clipboard, pyreadline.console.ironpython_console
missing module named 'org.python' - imported by pickle
missing module named fcntl - imported by tempfile, subprocess
missing module named riscosenviron - imported by os
missing module named riscospath - imported by os
missing module named riscos - imported by os
missing module named ce - imported by os
missing module named _emx_link - imported by os
missing module named os2 - imported by os
missing module named posix - imported by os
missing module named resource - imported by posix

Trying to get the TRACE output with

pyinstaller --name Check -i Check.ico --log-level=TRACE main.py > x.txt

produces an empty x.txt file.
Is there another way?

OK got it.
It was the STDERR that we wanted.
z.txt

This is a better one.
The other was created from a link, so some addresses are wrong...
err.txt

@xoviat
So, did you discover anything in the log?

Honestly it's going to be a few weeks until I will be able to look at this. I have some other things I need to take care of first.

Its OK, as long as you find what's wrong with this...
I'll postpone the update to v3 for the time being.

Update:
After installing the python 2.7.13 x86 from scratch and all the dependencies, PyInstaller compiles the executable just fine!
I'm sorry for your lost time and thank you for your efforts....

@htgoebel Please close this.

Was this page helpful?
0 / 5 - 0 ratings