missing modules after converting .py to .exe with pyinstaller - python

I am using pyinstaller to convert .py to .exe however after converting, when I then run the .exe, a command line window pops up for a split second and closes. the .exe isn't working almost at all, I then navigate to the warn.txt file and it says that there are a bunch of missing modules:
missing module named resource
missing module named posix
missing module named _posixsubprocess
missing module named cv2
and allot more (24 in total)
I've researched this problem and could not get a good answer iv tried converting with --onefile and --onedir and the same thing happens.
how do I import or fix these missing modules so that the .exe will run correctly or even at all?

Try to make a spec file and use hidden_imports for the modules you are missing:
# -*- mode: python -*-
import sys
sys.setrecursionlimit(5000)
block_cipher = None
a = Analysis(['src\\main.py'],
pathex=['your_path_text'],
binaries=[],
datas=[],
hiddenimports=['cv2','your_missing_modules...],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='main',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='main')
Then run pyinstaller main.spec.

Related

using --onefile for pyinstaller does not create a single executable, instead it keeps creating a directory

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.

PyInstaller dist EXE disappears

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 )

is there a way to record video after creating exe using pyinstaller

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

Cannot use lightgbm.dll in Pyinstaller's exe

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

pyinstaller still opening console despite using recommended methods to stop this

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.

Categories

Resources