I have 2 files, One is Main.py other one is Autoe.ui, I want both as a single .exe
I tried
pyinstaller -w --add-data="Autoe.ui;." Main.py
This works just fine, but it creates lot of other files as well, I wanted just a single exe, So I tried this
pyinstaller.exe -w --onefile --add-data="Autoe.ui;." Main.py
This creates a single .exe but it won't run, I get a pop-up saying "Failed to execute script Main"
I had a similar problem with the Kivy app. In my case it was a kv file, not a ui. Maybe what I did will help you.
In the folder with the * .py file I ran the command:
pyinstaller --onefile -y --clean --windowed --icon=someicon.ico main.py
The main.spec file appeared in the folder. I have edited it.
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(["main.py"],
pathex=["C:\\Users\\underground\\Desktop\\gdc"], #<<<<<<<path to folder of your app
binaries=[]
datas=[],
hiddenimports=[],
hookspath=[],
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)
a.datas += [('gdc.kv', 'C:\\Users\\underground\\Desktop\\gdc\\gdc.kv', 'DATA')] #<<<< I added kv file to a.datas
excluded_binaries = ['VCRUNTIME140.dll'] #<<<< I disabled this library because my app won't start on win10
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])
exe = EXE(pyz, Tree('C:\\Users\\underground\\Desktop\\gdc\\Data','Data'),
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
upx_exclude=[],
runtime_tmpdir=None,
console=False , icon='ikona.ico')
When I edited the spec file, I ran pyintaller again but gave the spec file instead of the * .py file.
pyinstaller main.spec
...that's all.
You can also try the GUI version - auto-py-to-exe instead of pyinstaller.
Related
Was given a choice to build a GUI application for a scientific project and I chose PyQt and PyInstaller to design, build and distribute the application.
Now I have created a GUI application using PyQt5 that came with Anaconda distribution. I have created an EXE using PyInstaller for my first GUI application and used the following command to create the EXE.
pyinstaller -wF main.spec
I run the above command in the project directory using PyCharm terminal.
However, once I run the exe by either double-click or through CMD using admin privileges, it just disappears. No error mentioned on the console or fatal error exceptions dialogs displayed. It just disappears. Why does this happen, and what should I do about this.
NOTE: using pyinstaller - 3.5
SPEC file:
# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(5000)
block_cipher = None
a = Analysis(['main.py'],
pathex=['C:\\Users\\username\\Documents\\Python-Sandbox-Honai'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
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,
a.binaries,
a.zipfiles,
a.datas,
[],
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
I am trying to get Pyinstaller 3.5 to create a "onefile" executable but it keeps generating a "onedir" instead.
My files are all in one directory. There is a main program that imports two other modules which in turn import a third. The program functions properly when run directly in Python 3.7.4. The "onedir" version generated by Pyinstaller also works. I'm running 64 bit Windows 10 Pro on a Surface Book 2.
The command I'm using to generate the file is:
pyinstaller --onefile --windowed --additional-hooks-dir=. qualys_admin.spec
My program uses wx, pubsub, xmltodict, requests, and pandas. The additional hook file is for xlrd which pandas needs to read a xlsx file.
My spec file looks like this:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
# work-around for https://github.com/pyinstaller/pyinstaller/issues/4064
import distutils
if distutils.distutils_path.endswith('__init__.py'):
distutils.distutils_path = os.path.dirname(distutils.distutils_path)
addedfiles = ('qualys_admin.ini', '.')
a = Analysis(['qualys_admin.py'],
pathex=['C:\\Users\\secops-sw\\Documents\\qualys-
administration\\qualysadmin'],
binaries=[],
datas=[addedfiles],
hiddenimports=[],
hookspath=[],
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='qualys_admin',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='qualys_admin')
I wrote a tiny "hello world" program to take the complexity of my program off the table. I was able to generate both a "onedir" and a "onefile" successfuly. So I know where to look for the standalone executable.
For my qualys_admin app, that executable is definitely not being generated and I cannot find any warnings to indicate why.
Does anyone have any ideas?
It is not working because your spec file is configured for one directory mode. You need to create the spec file with the one file flag.
pyi-makespec --onefile yourscript.py
Then you can modify your spec sheet and build the app using the custom spec sheet.
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 )
```
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')]
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.
I am trying to convert my code into an exe using pyinstaller spec.
I ran pyinstaller with the following command:
pyinstaller --clean --add-data lib_lightgbm.dll;\compile orca.spec
The exe fails with the error:
main__.PyInstallerImportError: Failed to load dynlib/dll
'C:\\Users\\...\\lightgbm\\../compile\\lib_lightgbm.dll'. Most probably this
dynlib/dll was not found when the application was frozen.
I have tried adding lightgbm.dll through binaries, but didnt work. I also tried manually copying it to the destination after the exe is created. That didnt work either. Most of the questions about pyinstaller and lib_lightgbm.dll failed to answer my issue. Can someone please suggest a solution? I am at my wits end at the moment.
Here is my spec file:
# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)
block_cipher = None
a = Analysis(['mycode.py'],
pathex=['C:\\mycode\\source code'],
binaries=[],
datas=[],
hiddenimports=['cython', 'sklearn', 'sklearn.feature_extraction','sklearn.pipeline', 'sklearn.ensemble', 'sklearn.neighbors.typedefs', 'sklearn.neighbors.quad_tree', 'sklearn.tree._utils'],
hookspath=[],
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='mycode',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='mycode')
When you build from a spec file, those options cannot be changed.
so either add the tuple to the datas section, or ommit the spec file and use all the parameters for pyinstaller
I'm not 100% sure this is the fix, but there should be something in your datas section of you spec file. So I'd investigate that. you can also build from a spec file using pyinstaller <spec file here> when you're done editing it.
https://pyinstaller.readthedocs.io/en/stable/spec-files.html
I have programmed a python script using tkinter and want to turn it into an exe file. I have tried running it as a .pyw file and it only runs the GUI window without the command line which is what I want. However, when using Pyinstaller to convert my script to a .exe file it opens and runs fine but the command line always opens as well. This has happened when converting both .py and .pyw files and it also occurs when I specify in the command prompt --windowed or --noconsole. I have even tried to edit the spec file of my .exe to see if the console is set to true but I find in the code "console=False". I cannot find any other fixes on previous questions or on the pyinstaller issus page and so I have had to ask myself.
This is the spec file
# -*- mode: python -*-
block_cipher = None
a = Analysis(['D:\\zebsu\\Documents\\simple_calculator_3.py'],
pathex=['C:\\Users\\zebsu'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
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='simple_calculator_3',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='simple_calculator_3')
I'm fairly new to Pyinstaller myself but the following command has worked for me:
pyinstaller -w YourPythonFile.py.
Hope this helps.