I was trying to warp a python file to an .exe file. But with these two lines, I encountered this problem.
import cv2
exit()
Traceback (most recent call last):
File "d:\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "d:\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "d:\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "d:\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 758, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "d:\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 705, in build
exec(code, spec_namespace)
File "D:\solar_cell\main.spec", line 7, in <module>
a = Analysis(['main.py'],
File "d:\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 254, in __init__
self.__postinit__()
File "d:\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 159, in __postinit__
self.assemble()
File "d:\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 433, in assemble
self.graph.process_post_graph_hooks(self)
File "d:\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 373, in process_post_graph_hooks
module_hook.post_graph(analysis)
File "d:\anaconda3\lib\site-packages\PyInstaller\depend\imphook.py", line 451, in post_graph
self._load_hook_module()
File "d:\anaconda3\lib\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module
self._hook_module = importlib_load_source(
File "d:\anaconda3\lib\site-packages\PyInstaller\compat.py", line 637, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 522, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1027, in load_module
File "<frozen importlib._bootstrap_external>", line 852, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "d:\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.py", line 14, in <module>
from PyInstaller.utils.hooks.qt import pyqt5_library_info, get_qt_binaries
File "d:\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 122, in <module>
pyqt5_library_info = Qt5LibraryInfo('PyQt5')
File "d:\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 50, in __init__
if hooks.is_module_satisfies("PyQt5 >= 5.15.4"):
File "d:\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 533, in is_module_satisfies
version = get_module_attribute(module_name, version_attr)
File "d:\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 329, in get_module_attribute
raise AttributeError(
AttributeError: Module 'PyQt5' has no attribute '__version__'
If I just print something like: print('dsfdsfs')
, then it can be wrapped to an .exe successfully.
My environment:
win10
pyinstaller 5.0.dev0
opencv-python 4.5.2.54
pyqt 5.9.2
And I was using anaconda prompt to do so.
The absolute easiest solution is to create a brand new environment, fortunately this is quite easy in anaconda, and pip install pyqt5. This should resolve any issues.
Seems like pyinstaller is having trouble finding your modules. You could check if pyinstaller works properly on a simple demo app to rule out your installation problems. If that works try putting this line at the top of your main.py file you are trying to run pyinstaller on.. Sorry, something went wrong.
It seems you are mixing some QT4 and QT5 here as your import is in QT5-style, but QtGui.QWidget looks like QT4-style.
I'm using pyinstaller and anaconda prompt and found the same issue, to solve it you must
pip install PyQt5 --user --use-feature=2020-resolver
and then run pyinstaller again.
Try using "pip install PyQt5" and then run again
I solved this problem by manually adding __version__ = "5.15.4"
to venv/Lib/site-packages/PyQt5/__init__.py
where venv
is a virtual environment in which PyQt5 is installed.
Before:
...
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# Support PyQt5 sub-packages that have been created by setuptools.
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
def find_qt():
...
After:
...
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# Support PyQt5 sub-packages that have been created by setuptools.
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
__version__ = "5.15.4"
def find_qt():
...
After loosing too many hours on this I updated PyInstaller and voilà it worked.
Unfortunately it seems that PyQt5 module on Anaconda is busted and missing various files that might be required by other modules, in my case PySimpleGui. The absolute easiest solution is to create a brand new environment, fortunately this is quite easy in anaconda, and pip install pyqt5. This should resolve any issues. Also install the rest of your packages and you should be good to go!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With