Tania Rheeder
Tania Rheeder

Reputation: 605

Windows- Pyinstaller Error “failed to execute script ” When App Clicked

I’m New to Python Coding and just finished my first python scripted I’m trying to publish my programme so that I can install in on another device.

But as soon as I convert it from .py to .exe with pyinstaller and try to run my programme it gives me the error:

fatal error: failed to execute scrip

Code I used in to convert:

pyinstaller -w file_name.py
pyinstaller -F file_name.py
pyinstaller -i "c:\\icon_file path" file_name.py

am I just missing as step or is there something else I can try to resolve this problem? I usually code on Visual studio and when I test run everything worked fine.

My .spec file:

    block_cipher = None


    a = Analysis(['file_name.py'],
                 pathex=['C:\\Users\\MainUser\\Desktop\\Publishing'],
                 binaries=[],
                 datas=[],
                 hiddenimports=[],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],                
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    a.binaries = a.binaries + 
                 [('libsha1.dll','/home/iot/lib/libsha1.dll','BINARY')]
    pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
    exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='file_name',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )
```

Upvotes: 2

Views: 7726

Answers (2)

Nicholas
Nicholas

Reputation: 3737

I am guessing you only have one script, so if you use:

Pyinstaller --onefile yourScript.py

Replacing yourScript.py with the name of your python file in the CMD/Terminal, you shouldn't have any problems.

If you are missing a binary, this should help. For example pyinstaller was missing the currency converter module, so I found and it, got the zip file and then ran this in CMD:

Pyinstaller --add-binary "C:\Users\myName\Downloads\eurofxref-hist.zip";currency_converter --onefile myScript.py

Where myScript.py is my Python script, and the link is to the folder with the binary zip file.

Upvotes: 0

jeremyjone
jeremyjone

Reputation: 313

Usually, this is due to a lack of file when packaging.

When you use PyInstaller, you can use it like this:

python -m PyInstaller .\yourFile.py

then, a yourFile.spec file is generated under this folder.

you should edit this file, add all project file into datas,

a = Analysis(['yourFile.py'],
         pathex=['D:\\projectPath\\project'],
         binaries=[],
         datas=[('D:\\projectPath\\project\\*.py', '.'),
                ('D:\\projectPath\\project\\UI\\*.ui', 'UI'),
                ('D:\\projectPath\\project\\other\\*.py', 'other'),
         ],
         ...
    )

It's simulated up here, a project that contains the UI and other folders. It like a tuple, ('full path', 'folder name').

If you have *.dll on Windows or *.so on Linux, you must be write into binaries:

a.binaries = a.binaries + [('libsha1.so','/home/iot/lib/libsha1.so','BINARY')]

Upvotes: 1

Related Questions