I used pyinstaller to create an executable for the linux environment. If I run it from the terminal (commandline) in addition to working correctly I also see all the images that are recalled by the various scripts. But when I run it from a launcher (Adeskbar) I only see the text part but not the images
Also, in addition to jpg images there are also png images, but I don't know how to insert them on [].
Below is my .spec file
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['index.py'],
pathex=['/opt/myprogram'],
binaries=[],
datas=[('/opt/myprogram/*.jpg', '.'),],
hiddenimports=['sip'],
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='index',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False )
and this is the batch for pyinstaller
#! /bin/sh
pyinstaller --onefile --windowed --hidden-import=sip index.spec
I tried with --onedir but nothing
Related
I have an ML solution. I use Pytesseract in this solution. I need to create an executable from it. So I use the pyinstaller. To create an executable that can call another exe, the tesseract exe, I followed the https://stackoverflow.com/a/60679256/13080899. When I create the exe with console Tesseract exe is called in my exe and gives me output but if I create the exe without console Tesseract doesn't work. I couldn't find any solution. How can I solve the problem?
Here is the my .spec file:
# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(5000)
block_cipher = None
a = Analysis(['Cam_Choice.py'],
pathex=['D:\\Project\\XXX'],
binaries=[('config\\tesseract\\tesseract.exe', 'config\\tesseract')],
datas=[],
hiddenimports=['boto3'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
a.datas += [('logo.ico', 'D:\\Project\\img\\logo.ico', "DATA")]
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='XXX',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
icon='D:\\Project\\img\\logo.ico')
P.S: Because of non-console mode I can't debug the exe.
Here is the solution:
#run_once
def get_tesseract_version():
"""
Returns LooseVersion object of the Tesseract version
"""
try:
return LooseVersion(
subprocess.check_output(
[tesseract_cmd, '--version'],
stderr=subprocess.STDOUT,
env=environ,
stdin=subprocess.DEVNULL,
)
.decode('utf-8')
.split()[1]
.lstrip(string.printable[10:]),
)
except OSError:
raise TesseractNotFoundError()
Added stdin=subprocess.DEVNULL, line to the Python\Python36\Lib\site-packages\pytesseract\pytesseract.py.
For more information: https://github.com/pyinstaller/pyinstaller/issues/5601
I writed a program with python which using selenium library. Basically, I am opening a page using Chromedriver.exe and login to a site. I want to use this program in another computer without use python. I want to convert it to a stand-alone exe type.
I tried pyinstaller --onefile filename.py
I got a dist folder which include .exe file. Also I have an .spec file. When I try to run exe file, nothing happen. Just a command panel is opening. How can I run this exe file?
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['borsaBot_Zpro.py'],
pathex=
['C:\\Users\\90544\\OneDrive\\Masaüstü\\Yusuf\\ödevler\\borsaBot'],
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='borsaBot_Zpro',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
I have a python script and a python spec file. The spec file contains some code which adds a couple of directories needed for my script. When i do
pyinstaller script.spec script.py
it creates a directory like normal. However when i do
pyinstaller --onefile script.spec script.py
it dosent create a single executable, instead it does the same thing as if i didnt include it.
is it something to do with my command line or is it something with the spec file?
spec file code:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['memrise.py'],
pathex=['C:\\Users\\blahblahpath\\memrise'],
binaries=[],
datas=[('C:\\Users\\blahblahpath\\memrise\\chromedriver_win32\\','.\\selenium\\webdriver\\')],
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='memrise',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
Tree('C:\\Users\\blahblahpath\\memrise\\assets', prefix='assets\\'),
Tree('C:\\Users\\blahblahpath\\langdetect', prefix='langdetect\\'),
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='memrise')
Your command is correct.
What you need to do is to check the dict file,
there should be a lot of files inside if you don't use --onefile
but there should only be one .exe file inside if you use.
I am using Kivy for GUI and developed an desktop exe successfully. The code runs fine which starts camera and even it records video and saves it. But when I create exe, recording is not working. And recorded video needs to be saved but it just saves the file which is actually empty.
I am using windows 10, Anaconda 3.5.5.
this is .spec file
# -*- mode: python -*-
from kivy.deps import sdl2, glew, gstreamer
block_cipher = None
a = Analysis(['ninth.py'],
pathex=['D:\\Somu_Sir\\new_project'],
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='ninth',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
coll = COLLECT(exe, Tree('D:\\Somu_Sir\\new_project\\required_files\\'),
a.binaries,
a.zipfiles,
a.datas,
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins + gstreamer.dep_bins)],
strip=False,
upx=True,
name='ninth')
Application is starting but only record function is not working. Expected output should be a video stored in same folder
Yes you have to use binaries=[] where you need to pass the .dll files which are required for your application to run. Your code works fine that means your app should also work. only when creating .exe file using PyInstaller you need to give all required files as hiddenimports as well if you want only one single file. You can try binaries=[], where you can add number of .dll dependencies or even through cmd for example:
pyinstaller --add-binary <PATH_TO_PYTHON>\Lib\site-packages\cv2\opencv_ffmpeg320_64.dll
opencv_ffmpeg320_64.dll can help you to record camera videos
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.