feiyuhuahuo
feiyuhuahuo

Reputation: 141

AttributeError: Module 'PyQt5' has no attribute '__version__'

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.

Upvotes: 11

Views: 17562

Answers (7)

ericK
ericK

Reputation: 1

I'm seeing the same issue. pip install PyQt5 errored out... Pyinstaller team needs some serious help. Reverting back to previous version of Pyinstaller that works on my system.

Traceback (most recent call last):
  File "c:\progra~1\anacon~1\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\progra~1\anacon~1\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\PROGRA~1\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\__main__.py", line 126, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\building\build_main.py", line 815, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\building\build_main.py", line 762, in build
    exec(code, spec_namespace)
  File ".\tibcoAtlassian.spec", line 17, in <module>
    noarchive=False)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\building\build_main.py", line 294, in __init__
    self.__postinit__()
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\building\datastruct.py", line 159, in __postinit__
    self.assemble()
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\building\build_main.py", line 473, in assemble
    self.graph.process_post_graph_hooks(self)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\depend\analysis.py", line 373, in process_post_graph_hooks
    module_hook.post_graph(analysis)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\depend\imphook.py", line 451, in post_graph
    self._load_hook_module()
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\depend\imphook.py", line 409, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\compat.py", line 632, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\hooks\hook-PyQt5.py", line 11, in <module>
    from PyInstaller.utils.hooks.qt import pyqt5_library_info, \
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 162, in <module>
    pyqt5_library_info = QtLibraryInfo('PyQt5')
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 54, in __init__
    if hooks.is_module_satisfies("PyQt5 >= 5.15.4"):
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 502, in is_module_satisfies
    version = get_module_attribute(module_name, version_attr)
  File "c:\progra~1\anacon~1\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 353, in get_module_attribute
    'Module %r has no attribute %r' % (module_name, attr_name))
AttributeError: Module 'PyQt5' has no attribute '__version__'

Upvotes: 0

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!

Upvotes: 1

Marlon
Marlon

Reputation: 11

After loosing too many hours on this I updated PyInstaller and voilà it worked.

Upvotes: 1

naderabdalghani
naderabdalghani

Reputation: 1189

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():
...

Upvotes: 3

Nestor Mej&#237;a
Nestor Mej&#237;a

Reputation: 125

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.

Upvotes: 12

egg
egg

Reputation: 11

I figured out a fix. When you convert your .py file to .exe with auto-py-to-exe you have to click "advanced" then add "hidden-imports" there you add the things you import in your .py file, for example, my .py file imports "sounddevice" "numpy" and "os", so I add all of those into the "hidden-imports" in auto-py-to-exe" I hope this helped - here is a picture: example

Upvotes: -1

pjrockzzz
pjrockzzz

Reputation: 165

Try using "pip install PyQt5" and then run again

Upvotes: 6

Related Questions