【问题标题】:PyInstaller and OpenGL Error. ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'PyInstaller 和 OpenGL 错误。 ImportError:无法从“PyInstaller.utils.hooks”导入名称“opengl_arrays_modules”
【发布时间】:2020-11-13 01:36:07
【问题描述】:

我使用这个命令安装了最新版本的 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:\Users\8Observer8\AppData\Roaming\Python\Python37\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\8Observer8\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:\Users\8Observer8\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:\Users\8Observer8\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:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
  File "C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__     
    self.assemble()
  File "C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\building\build_main.py", line 418, in assemble
    self.graph.process_post_graph_hooks()
  File "C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\analysis.py", line 365, in process_post_graph_hooks
    module_hook.post_graph()
  File "C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\depend\imphook.py", line 440, in post_graph
    self._load_hook_module()
  File "C:\Users\8Observer8\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:\Users\8Observer8\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:\Users\8Observer8\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:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\PyInstaller\utils\hooks\__init__.py)

【问题讨论】:

    标签: python opengl pyinstaller


    【解决方案1】:

    使用python 3.8.5:

    我尝试升级钩子:

    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 --onefile --windowed --noupx main.py 构建了我的示例当我尝试运行main.exe 时出现错误:Fatal error detected. Failed to execute script pyi_rth_pkgres。但我发现我可以使用加法键并且它可以工作:pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --windowed --noupx main.py
    • 这对我来说非常有效。我想知道为什么他们还没有将 2020.8 版本上传到 Pypi。
    • @8Observer8 请提供您的参考资料,以及您使用的 python 版本。 stackoverflow.com/questions/37815371/…
    • @sancelot 我使用的是 3.7.8
    • 不错的简单修复。谢谢!
    【解决方案2】:

    Pyinstaller 开发人员最近对挂钩进行了更改。用于 OpenGL 的已移至 https://github.com/pyinstaller/pyinstaller-hooks-contrib 。我相信您仍然拥有以前安装 pyinstaller 的旧挂钩。这个不起作用,因为他们也对代码进行了更改。您应该删除 OpenGL 挂钩 (C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py) 或删除 pyinstaller 并重新安装。然后获取 github 的 contrib 表单并用--additional-hooks-dir 指向它

    【讨论】:

    • 非常感谢。有用。我的步骤:(1)我删除了hook-OpenGL.py文件,(2)pip uninstall pyinstaller,(3)pip install pyinstaller,(4)我向PyInstaller添加了一个新密钥--hidden-import=pkg_resources.py2_warn,因为我遇到了运行时错误Failed to execute script pyi_rth_pkgres .现在命令看起来像这样:pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --windowed --noupx main.py 它适用于来自 PySDL2 和 PySide2 的 OpenGL
    【解决方案3】:

    它不适用于 wxPython。 我做了这一切。 我看到了

    它适用于 PySDL2 和 PySide2 的 OpenGL

    【讨论】:

    • 试试这个命令序列:(1) pip uninstall pyinstaller-hooks-contrib (2) git clone https://github.com/pyinstaller/pyinstaller-hooks-contrib.git (3) cd pyinstaller-hooks-contrib (4) python setup.py install (5) pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --windowed --noupx main.py
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 2020-12-06
    相关资源
    最近更新 更多