PyInstaller and OpenGL Error. ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'
PyInstaller and OpenGL Error. ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'
我使用以下命令安装了最新版本的 PyInstaller:pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
我尝试使用以下命令捆绑最简单的代码:pyinstaller --onefile --noupx main.py
main.py
from OpenGL import GL
print("Hello, OpenGL")
我收到这个错误:ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'
完整日志:
PS E:\_Projects\Python\SDL2\pyopengl_demo> pyinstaller --onefile main.py
124 INFO: PyInstaller: 4.0.dev0
124 INFO: Python: 3.7.8
138 INFO: Platform: Windows-10-10.0.18362-SP0
140 INFO: wrote E:\_Projects\Python\SDL2\pyopengl_demo\main.spec
283 INFO: UPX is available.
287 INFO: Extending PYTHONPATH with paths
['E:\_Projects\Python\SDL2\pyopengl_demo',
'E:\_Projects\Python\SDL2\pyopengl_demo']
338 INFO: checking Analysis
339 INFO: Building Analysis because Analysis-00.toc is non existent
340 INFO: Initializing module dependency graph...
351 INFO: Caching module graph hooks...
401 INFO: Analyzing base_library.zip ...
5023 INFO: Processing pre-find module path hook distutils from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
5039 INFO: distutils: retargeting to non-venv dir 'c:\program files (x86)\python37-32\lib'
7945 INFO: Caching module dependency graph...
8243 INFO: running Analysis Analysis-00.toc
8248 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\program files (x86)\python37-32\python.exe
8445 INFO: Analyzing E:\_Projects\Python\SDL2\pyopengl_demo\main.py
16293 INFO: Processing pre-find module path hook site from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
16308 INFO: site: retargeting to fake-dir 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\fake-modules'
18941 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-setuptools.extern.six.moves.py'.
24985 INFO: Processing module hooks...
24988 INFO: Loading module hook 'hook-OpenGL.py' from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
Traceback (most recent call last):
File "c:\program files (x86)\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files (x86)\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 716, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 663, in build
exec(code, spec_namespace)
File "E:\_Projects\Python\SDL2\pyopengl_demo\main.spec", line 17, in <module>
noarchive=False)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
self.__postinit__()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 418, in assemble
self.graph.process_post_graph_hooks()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\analysis.py", line 365, in process_post_graph_hooks
module_hook.post_graph()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\imphook.py", line 440, in post_graph
self._load_hook_module()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\imphook.py", line 407, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\compat.py", line 588, 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:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py", line 24, in <module>
from PyInstaller.utils.hooks import opengl_arrays_modules
ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks' (C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\utils\hooks\__init__.py)
Pyinstaller 开发人员最近对挂钩进行了更改。用于 OpenGL 的已移至 https://github.com/pyinstaller/pyinstaller-hooks-contrib 。我相信你仍然有以前安装的 pyinstaller 的旧钩子。这一个将不起作用,因为他们还对代码进行了更改。您应该删除 OpeenGL 挂钩 (C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py
) 或删除 pyinstaller 并重新安装。然后获取贡献表单 github 并使用 --additional-hooks-dir
指向它
它不适用于 wxPython。
我做了所有这些。
我看到了
It works with OpenGL from PySDL2 and PySide2
使用 python 3.8.5:
我尝试升级 hooks :
pip install -U pyinstaller-hooks-contrib
升级挂钩,回复
Requirement already up-to-date: pyinstaller-hooks-contrib in c:\python38\lib\site-packages (2020.7)
我删除了 pip 版本:
pip uninstall pyinstaller-hooks-contrib
所以,我必须更新存储库文件:
git clone https://github.com/pyinstaller/pyinstaller-hooks-contrib.git
cd pyinstaller-hooks-contrib
python setup.py install
我现在2020.8版本设置好了,初始问题解决了
我使用以下命令安装了最新版本的 PyInstaller:pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
我尝试使用以下命令捆绑最简单的代码:pyinstaller --onefile --noupx main.py
main.py
from OpenGL import GL
print("Hello, OpenGL")
我收到这个错误:ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'
完整日志:
PS E:\_Projects\Python\SDL2\pyopengl_demo> pyinstaller --onefile main.py
124 INFO: PyInstaller: 4.0.dev0
124 INFO: Python: 3.7.8
138 INFO: Platform: Windows-10-10.0.18362-SP0
140 INFO: wrote E:\_Projects\Python\SDL2\pyopengl_demo\main.spec
283 INFO: UPX is available.
287 INFO: Extending PYTHONPATH with paths
['E:\_Projects\Python\SDL2\pyopengl_demo',
'E:\_Projects\Python\SDL2\pyopengl_demo']
338 INFO: checking Analysis
339 INFO: Building Analysis because Analysis-00.toc is non existent
340 INFO: Initializing module dependency graph...
351 INFO: Caching module graph hooks...
401 INFO: Analyzing base_library.zip ...
5023 INFO: Processing pre-find module path hook distutils from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
5039 INFO: distutils: retargeting to non-venv dir 'c:\program files (x86)\python37-32\lib'
7945 INFO: Caching module dependency graph...
8243 INFO: running Analysis Analysis-00.toc
8248 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\program files (x86)\python37-32\python.exe
8445 INFO: Analyzing E:\_Projects\Python\SDL2\pyopengl_demo\main.py
16293 INFO: Processing pre-find module path hook site from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
16308 INFO: site: retargeting to fake-dir 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\fake-modules'
18941 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-setuptools.extern.six.moves.py'.
24985 INFO: Processing module hooks...
24988 INFO: Loading module hook 'hook-OpenGL.py' from 'C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
Traceback (most recent call last):
File "c:\program files (x86)\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\program files (x86)\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 716, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 663, in build
exec(code, spec_namespace)
File "E:\_Projects\Python\SDL2\pyopengl_demo\main.spec", line 17, in <module>
noarchive=False)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
self.__postinit__()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 418, in assemble
self.graph.process_post_graph_hooks()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\analysis.py", line 365, in process_post_graph_hooks
module_hook.post_graph()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\imphook.py", line 440, in post_graph
self._load_hook_module()
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\imphook.py", line 407, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\compat.py", line 588, 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:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py", line 24, in <module>
from PyInstaller.utils.hooks import opengl_arrays_modules
ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks' (C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\utils\hooks\__init__.py)
Pyinstaller 开发人员最近对挂钩进行了更改。用于 OpenGL 的已移至 https://github.com/pyinstaller/pyinstaller-hooks-contrib 。我相信你仍然有以前安装的 pyinstaller 的旧钩子。这一个将不起作用,因为他们还对代码进行了更改。您应该删除 OpeenGL 挂钩 (C:\UsersObserver8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py
) 或删除 pyinstaller 并重新安装。然后获取贡献表单 github 并使用 --additional-hooks-dir
它不适用于 wxPython。 我做了所有这些。 我看到了
It works with OpenGL from PySDL2 and PySide2
使用 python 3.8.5:
我尝试升级 hooks :
pip install -U pyinstaller-hooks-contrib
升级挂钩,回复
Requirement already up-to-date: pyinstaller-hooks-contrib in c:\python38\lib\site-packages (2020.7)
我删除了 pip 版本:
pip uninstall pyinstaller-hooks-contrib
所以,我必须更新存储库文件:
git clone https://github.com/pyinstaller/pyinstaller-hooks-contrib.git
cd pyinstaller-hooks-contrib
python setup.py install
我现在2020.8版本设置好了,初始问题解决了