PyInstaller error with PySide
Question: I have been playing with PyInstaller on Windows 7 (64 bit). I am currently
using PyInstaller 3.1.1 with Python 2.7.6. I created an app that creates a
simple PySide GUI and generated a dist folder with an executable with this
command:

    
    
    > C:\Python27\Scripts\pyinstaller.exe .\HelloWidget.spec
    

This is what the spec file looks like:

    
    
    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(['HelloWidget.py'],
                 pathex=['C:\\Users\\spearsc\\Documents\\python_projects\\HelloWorldGui'],
                 binaries=None,
                 datas=[('.\\mainwindow.ui', '.')],
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              exclude_binaries=True,
              name='HelloWidget',
              debug=False,
              strip=False,
              upx=True,
              console=True )
    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   name='HelloWidget')
    

I wanted to use a spec file, so the .ui file would be bundled along with
everything else. However, when I run the executable, I get this error:

    
    
    > .\HelloWidget.exe
    Traceback (most recent call last):
      File "<string>", line 41, in <module>
      File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
     389, in load_module
      File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
      File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
      File "PySide-1.2.2\PySide\_utils.py", line 87, in get_pyside_dir
      File "PySide-1.2.2\PySide\_utils.py", line 83, in _get_win32_case_sensitive_name
      File "PySide-1.2.2\PySide\_utils.py", line 58, in _get_win32_short_name
    WindowsError: [Error 2] The system cannot find the file specified.
    pyi_rth_qt4plugins returned -1
    

What is confusing to me is that when I look in the dist folder, I see compiled
PySide and Qt files:

    
    
        Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
    
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -a---         5/23/2016   4:45 PM      80896 bz2.pyd
    -a---         5/24/2016   5:20 PM     795278 HelloWidget.exe
    -a---         5/24/2016   5:20 PM       1019 HelloWidget.exe.manifest
    -a---         5/24/2016   4:42 PM       4102 mainwindow.ui
    -a---         5/24/2016   5:20 PM       1052 Microsoft.VC90.CRT.manifest
    -a---         5/23/2016   4:45 PM     245760 msvcm90.dll
    -a---         5/23/2016   4:45 PM     853328 msvcp90.dll
    -a---         5/23/2016   4:45 PM     641360 msvcr90.dll
    -a---         5/24/2016   4:43 PM     248320 pyside-python2.7.dll
    -a---         5/24/2016   4:43 PM    3063808 PySide.QtCore.pyd
    -a---         5/24/2016   4:43 PM   12750848 PySide.QtGui.pyd
    -a---         5/24/2016   4:43 PM    1095168 PySide.QtNetwork.pyd
    -a---         5/24/2016   4:43 PM    1052672 PySide.QtUiTools.pyd
    -a---         5/23/2016   4:45 PM    3004928 python27.dll
    -a---         5/24/2016   4:43 PM    3469824 QtCore4.dll
    -a---         5/24/2016   4:43 PM   11679744 QtGui4.dll
    -a---         5/24/2016   4:43 PM    1473536 QtNetwork4.dll
    -a---         5/23/2016   4:45 PM      10752 select.pyd
    -a---         5/24/2016   4:43 PM     330752 shiboken-python2.7.dll
    -a---         5/23/2016   4:45 PM     689664 unicodedata.pyd
    -a---         5/24/2016   4:43 PM     111616 _ctypes.pyd
    -a---         5/23/2016   4:45 PM     474624 _hashlib.pyd
    

Any thoughts? Can I not trust what I see in the dist folder?

5/25/16:

Well, this is interesting. I put a print statement in the
_get_win32_short_name function.

    
    
    def _get_win32_short_name(s):
        """ Returns short name """
        print s
        buf_size = MAX_PATH
        for i in range(2):
            buf = create_unicode_buffer(u('\0') * (buf_size + 1))
            r = GetShortPathNameW(u(s), buf, buf_size)
            if r == 0:
                raise WinError()
            if r < buf_size:
                if PY_2:
                    return buf.value.encode(sys.getfilesystemencoding())
                return buf.value
            buf_size = r
        raise WinError()
    

Here is the result I got back after I built a new executable.

    
    
    > .\HelloWidget.exe
    C:\Users\spearsc\DOCUME~1\PYTHON~1\HELLOW~1\dist\HELLOW~1\PySide
    Traceback (most recent call last):
      File "<string>", line 41, in <module>
      File "c:\users\spearsc\appdata\local\temp\pip-build-djws3k\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line
     389, in load_module
      File "PySide-1.2.2\PySide\__init__.py", line 55, in <module>
      File "PySide-1.2.2\PySide\__init__.py", line 11, in _setupQtDirectories
      File "PySide-1.2.2\PySide\_utils.py", line 88, in get_pyside_dir
      File "PySide-1.2.2\PySide\_utils.py", line 84, in _get_win32_case_sensitive_name
      File "PySide-1.2.2\PySide\_utils.py", line 59, in _get_win32_short_name
    WindowsError: [Error 2] The system cannot find the file specified.
    pyi_rth_qt4plugins returned -1
    

The directory does not exist. Any ideas on how to get around that?


Answer: The trick is to add an empty PySide folder in the dist folder.

    
    
        Directory: C:\Users\spearsc\Documents\python_projects\HelloWorldGui\dist\HelloWidget
    
    
    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    d----         5/25/2016   2:46 PM            PySide
    -a---         5/23/2016   4:45 PM      80896 bz2.pyd
    -a---         5/25/2016   2:46 PM     795278 HelloWidget.exe
    -a---         5/25/2016   2:46 PM       1019 HelloWidget.exe.manifest
    -a---         5/24/2016   4:42 PM       4102 mainwindow.ui
    -a---         5/25/2016   2:46 PM       1052 Microsoft.VC90.CRT.manifest
    -a---         5/23/2016   4:45 PM     245760 msvcm90.dll
    -a---         5/23/2016   4:45 PM     853328 msvcp90.dll
    -a---         5/23/2016   4:45 PM     641360 msvcr90.dll
    -a---         5/24/2016   4:43 PM     248320 pyside-python2.7.dll
    -a---         5/24/2016   4:43 PM    3063808 PySide.QtCore.pyd
    -a---         5/24/2016   4:43 PM   12750848 PySide.QtGui.pyd
    -a---         5/24/2016   4:43 PM    1095168 PySide.QtNetwork.pyd
    -a---         5/24/2016   4:43 PM    1052672 PySide.QtUiTools.pyd
    -a---         5/25/2016   2:46 PM     542208 PySide.QtXml.pyd
    -a---         5/23/2016   4:45 PM    3004928 python27.dll
    -a---         5/24/2016   4:43 PM    3469824 QtCore4.dll
    -a---         5/24/2016   4:43 PM   11679744 QtGui4.dll
    -a---         5/24/2016   4:43 PM    1473536 QtNetwork4.dll
    -a---         5/25/2016   2:46 PM     506368 QtXml4.dll
    -a---         5/23/2016   4:45 PM      10752 select.pyd
    -a---         5/24/2016   4:43 PM     330752 shiboken-python2.7.dll
    -a---         5/23/2016   4:45 PM     689664 unicodedata.pyd
    -a---         5/24/2016   4:43 PM     111616 _ctypes.pyd
    -a---         5/23/2016   4:45 PM     474624 _hashlib.pyd
    

After I did that I ran the executable and got an import error for
PySide.QtXml, so I generated a new spec file and modified it.

    
    
    # -*- mode: python -*-
    
    block_cipher = None
    
    
    a = Analysis(['HelloWidget.py'],
                 pathex=['C:\\Users\\spearsc\\Documents\\python_projects\\HelloWorldGui'],
                 binaries=None,
                 datas=[('.\mainwindow.ui', '.')],
                 hiddenimports=['PySide.QtXml'],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              exclude_binaries=True,
              name='HelloWidget',
              debug=False,
              strip=False,
              upx=True,
              console=True )
    coll = COLLECT(exe,
                   a.binaries,
                   a.zipfiles,
                   a.datas,
                   strip=False,
                   upx=True,
                   name='HelloWidget')
    

I then used the spec file to create the executable again. I added the empty
PySide to the dist folder, and it worked!

