Compiling python using PyInstaller throws many WARNINGS - python

I am trying to create an EXE file from my python script which I wrote in PyCharm. I am using the newest version of Python and using PyInstaller on a virtualenv.
The problem occurs whenever I try to actually use the command pyinstaller --onedir map.spec with map.spec being the spec file of my script, included here:
block_cipher = None
a = Analysis(['map.py'],
pathex=['C:\\Users\\BGBSC\\Desktop\\untitled'],
binaries=[],
datas=[('nactiMapu.txt', '.'), ('nactiPohyb.txt', '.'), ('nactiZnacky.txt', '.'), ('a.txt', '.'), ('b.txt', '.'), ('c.txt', '.')],
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='map',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='map')
Whenever I try to run pyinstaller several warnings of this type show up:
5447 WARNING: lib not found: python38.dll dependency of C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.752.0_x64__qbz5n2kfra8p0\DLLs\_tkinter.pyd
With every one of them referencing python38.dll, only difference being that they are 'dependant' on a different module. It also writes this line, which is probably also cause for concern:
5623 INFO: Python library not in binary dependencies. Doing additional searching...
5631 INFO: Using Python library
My script uses these imports:
import sys
import os
import turtle
import time
It is a turtle script that draws something. I also manipulate different txt files that I included as datas so they get exported with the final exe (at least how I understand it).
I am probably missing something very basic or maybe the newest Python is just not supported with pyinstaller, or is it just not able to find my python38.dll (I added the paths to the environmental).

The Windows Store python is stated to be experimental and probably should be avoided for developers.
I would suggest downloading and using the Python from python.org for developers.

Related

Pyinstaller app works at terminal but not when double-clicking in finder

Mac Big Sur, python 3.9, pyinstaller 4.3.
I've seen this question posted elsewhere, e.g. PyInstaller OS X app runs from command line, but not Finder window, but can't quite understand the proposed solutions. I have a Mac .app created using tkinter and pyinstaller that functions fine at the terminal when I type
./dist/MyApplication.app/Contents/MacOS/MyApplication
However, when I double click on the .app in the Finder, the program icon appears briefly on my computer's dock before disappearing. No error message at all.
Here is my .spec file:
block_cipher = None
a = Analysis(['MyApplication.py'],
pathex=
['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages',
'/Users/fishbacp/Desktop'],
binaries=[],
datas=[('/Users/fishbacp/Desktop/background.png','.')],
hiddenimports=['_tkinter','PIL'],
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='MyApplication',
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,
upx_exclude=[],
name='MyApplication')
app =
BUNDLE(coll,name='MyApplication.app',
icon='/Users/fishbacp/Desktop/spectrum.ico',
bundle_identifier=None,
info_plist={'LSEnvironment': {'LANG': 'de_DE.UTF-8',
'LC_CTYPE': 'de_DE.UTF-8'}})
I had same problem (but used one folder mode instead of packaging as an .app), when double click in finder, it will open console and immediately close it.
And my case was due to uncaught exception in my program, which failed to load a file from the folder, and correct the path fixed the problem.
from pathlib import Path
# The file path should be relative to the packaged folder path
file_path = Path(__file__).resolve().with_name("some/path/to/the/file")
It might not be your case but my guess is your program exists due to unexpected condition and that's why it disappears soon, and file path is quite often not handled properly when using PyInstaller.
Hope it can help someone.

What does "Error loading Python lib" ... "image not found error" mean when attempting to run Mac app created using pyinstaller?

Python 3.9 on Mac Big Sur using most recent version of pyinstaller.
I have a functioning script name Read_CSV_Barplot.py, which I want to make into an .app using pyinstaller. When running pyinstaller, I receive some warnings but no error messages. Below is my .spec file, where I've modified pathex to include the directory site-packages where needed modules are stored. When attempting to run the resulting .app at the terminal I receive the following error message, which I'm trying to decipher:
Error loading Python lib '/Users/fishbacp/Desktop/dist/Read_CSV_Barplot.app/Contents/MacOS/Python': dlopen:
dlopen(/Users/fishbacp/Desktop/dist/Read_CSV_Barplot.app/Contents/MacOS/Python, 10): image not found
Here is the .spec file:
block_cipher = None
a = Analysis(['Read_CSV_Barplot.py'],
pathex=['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages', '/Users/fishbacp/Desktop'],
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='Read_CSV_Barplot',
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='Read_CSV_Barplot')
app = BUNDLE(exe,name='Read_CSV_Barplot.app',icon=None,bundle_identifier=None)
I've never encountered an error message of this type before, which is where my confusion lies.
Based upon a post at https://github.com/pyinstaller/pyinstaller/issues/2047, I changed exe to coll within Bundle in my spec file.
When trying to run the new application, I encountered a different error message, "_tkinter could not be found." I corrected this using brew install python-tk
Things now work fine.

Pyinstaller 3.5 will not generate a standalone executable

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.

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

PyQt5 Executable is crashing with Missing DLL

My issue is related to a pyqt5 executable I created with pyinstaller. The only command I'm using is:
pyinstaller script.py
I'm not very experienced with Pyinstaller's output messages. So I'm posting this question in case someone else can help me figure out what the missing modules or files are.
Here is copy of the entire Compile output:
Github - Pyinstaller Output
Here is a copy of the error that appears.. it happens like in a millisecond:
Any comments or help are appreciated. If you think you have a possible solution, please attempt an answer. I'm sure its worth looking into. Hopefully, its something simple and due to my lack of knowledge.
One other note, I'm importing/using the module ibm_db and the wrapper module ibm_db_dbi.
Here is a copy of my spec file:
# -*- mode: python -*-
block_cipher = None
added_files = [
(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', '.')
]
a = Analysis(['InheritMainWindow.py'],
pathex=['c:\\Python37\\PDFMaker_v3\\Prototype',
'C:\\Python37\\Lib\\site-packages\\',
'C:\\Python37\\Lib\\site-packages\\sqlalchemy\\connectors\\',
'C:\\Python37\\Lib\\site-packages\\clidriver\\',
'C:\\Python37\\Lib\\site-packages\\ibm_db_dlls',
'C:\\Python37\\Lib\\site-packages\\ibm_db.py'],
binaries=[('ibm_db.dll', 'ibm_db_dlls')],
datas=[],
hiddenimports=['ibm_db', 'ibm_db_dbi'],
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='InheritMainWindow',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
a.binaries = [x for x in a.binaries if os.path.dirname(x[1]).find("IBM") < 0]
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='InheritMainWindow')
PS you should be able to repeat the issue with the following:
import ibm_db
print('hello!')
in command prompt:
pyinstaller hello.py
Upon executing the exe inside the dist folder, you'll get the same above error.
Here is a list of the things I'm tried to resolve this:
1) Providing a full path in the binary like this:
binaries=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')]
This makes no difference the crash still occurs. And I was already seeing the ibm_db_dlls folder appear in my dist folder. So the binary is being added, but its just not being seen.
2) From the ibm developer forum here:
https://developer.ibm.com/answers/questions/448999/python-3-db2-windows-10-problems-and-script-compil/
A suggested solution was using the --clean option. I've tried this option on 'hello.py', where it only is importing the ibm_db package and it actually works as an exe. But this solution doesn't work on my main project.
Correction: This does NOT work even on the simple hello.py example.
Final update: I've provided a solution below!
So I solved the issue. And I'm expecting this should help a lot of folks. First part of solution is the PATHEX list. I had to update this list to point to all my system's IBM directories:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['InheritMainWindow.py'],
pathex=['c:\\Python37\\PDFMaker_v3',
'C:\\Python37\\Lib\\site-packages\\ibm_db_dlls',
'C:\\Program Files (x86)\\ibm\\gsk8\\lib',
'C:\\Program Files (x86)\\ibm\\gsk8\\bin',
'C:\\Program Files (x86)\\IBM Informix Client SDK\\bin',
'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN',
'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION',
'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN',
'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION',
'C:\\Program Files (x86)\\ibm\\gsk8\\lib',
'C:\\Program Files (x86)\\ibm\\gsk8\\bin',
'C:\\Program Files (x86)\\IBM Informix Client SDK\\bin'],
binaries=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')],
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='InheritMainWindow',
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,
name='InheritMainWindow')
The next part of the answer was really tricky in figuring out. Its found inside the imb_db.py file:
import os
if 'clidriver' not in os.environ['PATH']:
os.environ['PATH'] = os.environ['PATH'] + ";" + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp
__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')
__loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__)
__bootstrap__()
I had to update my path variable to include clidriver directory:
C:\Python37\Lib\site-packages\clidriver\bin
the imb_db.py is suppose to be adding this to the path, but its adding in in the wrong format or directory. So that the next line:
__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')
Ends up not finding the .dll file. So after making these two updates, the program runs and succesfully connects to a remote DB2 database.
#RockAndRoleCoder Thanks for your question and answer. I had met the same situation in Windows7 Python3.7 ibm-db 3.0.1
with your hint,I think the reason is that exe can't find *.dll in clidriver\bin and ibm_db.dll,
and solve it with a similar method in two steps
Frist:
the same as you, add clidriver directory to system path
**\site-packages\clidriver\bin
Second
pack with argument --add-binary
Pyinstaller --add-binary **\Lib\site-packages\ibm_db_dlls\ibm_db.dll;.\ibm_db_dlls myproject.py
Then it's OK!

Categories

Resources