Search code examples
pythonkivypyinstaller

Kivy One-Folder packaging with PyInstaller looks for _MEIxxxxxx path?


Looking to package a kivy application on windows, I ran PyInstaller --onedir <app-name>.spec on the following spec file:

# -*- mode: python ; coding: utf-8 -*-
from kivy_deps import sdl2, glew


block_cipher = None


a = Analysis(['temp-dir-for-packaging\\main.py'],
             pathex=[],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             hooksconfig={},
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts, 
          [],
          exclude_binaries=True,
          name='one-folder',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True,
          disable_windowed_traceback=False,
          target_arch=None,
          codesign_identity=None,
          entitlements_file=None )
coll = COLLECT(exe, Tree('temp-dir-for-packaging\\'),
               a.binaries,
               a.zipfiles,
               a.datas, 
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               upx_exclude=[],
               name='one-folder')

It generated files under dist directory. However, when I run the resulting exe, I get the following error:

Error loading Python DLL 'C:\Users\<username>\AppData\Local\Temp\_MEI86482\python39.dll'.
LoadLibrary: The specified module could not be found.

According to the PyInstaller docs, the default i.e, --onedir option should not create a temporary _MEIxxxxxx directory to begin with.

Where could I have gone wrong?


Solution

  • It sounds like there may be some confusion with .spec files. According to the docs:

    When you create a spec file, most command options are encoded in the spec file. When you build from a spec file, those options cannot be changed. If they are given on the command line they are ignored and replaced by the options in the spec file.

    Only the following command-line options have an effect when building from a spec file:

    --upx-dir

    --distpath

    --workpath

    --noconfirm

    --ascii

    --clean

    The spec file that you posted is for creating a onedir executable, and adding the --onedir option has no effect.

    I suggest removing the build and dist folders, along with the .spec file. Then create a new spec file using pyi-makespec --onedir.Then edit that newly created .spec file as needed. Then run pyinstaller <app-name>.spec with no command line options. This should create a dist folder with nothing in it other than another folder with the name of your main python file. Inside that folder you should find all the files needed to run your app, including a python39.dll file and an exe file.