2

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 )
```
3
  • Can you share the code you use please for pyinstaller? Commented May 15, 2019 at 14:42
  • pyinstaller -w My_File_Name.py ; pyinstaller -F My_File_Name.py ; pyinstaller -i "Path for my Icon_image" My_File_Name.py Commented May 16, 2019 at 7:58
  • Does this answer your question? Windows- Pyinstaller Error "failed to execute script " When App Clicked Commented May 29, 2020 at 21:16

2 Answers 2

1

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')]
Sign up to request clarification or add additional context in comments.

4 Comments

This Might be a silly question, but the path I should enter ”” 'D:\\projectPath\\project' “” is it where my file is publish and I made the .exe file or the one where I originally saved it and all the files I used?
I have added my .spec file in my main question
@TaniaRheeder Maybe I didn't make myself clear, you need run python -m PyInstaller twice, The first time we did that I told, The Second you should run python -m PyInstaller yourFile.spec.
@TaniaRheeder ` 'D:\\projectPath\\project'` is your project root path, the *.exe will build in ./dist/startFileName/ *.exe
0

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.

6 Comments

Should I run this with a setup.py file? It only flesh command prompt for 2 sec and the nothing happens.
You shouldn't have to. Create a new folder on your desktop, put your script into it, then open up the CMD in that folder, the paste that code I linked with the script name changed. It should work?
So my CMD just gave me a new Error. My data is stored in mySql. Error : No module named mysql.connector but it runs fine when I test it in Visual Studio. And i did pip install It before hand
Oh, I see. Sounds like you do not have the supported binary. You need to find the binary zip file of mysql.connector. I have edited my response to help with the code you need to use when you have it
I just pip Install MySQL-connector and it run, Thank you!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.