3

I installed the latest version of PyInstaller using this command: pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

I try to bundle the simplest code using this command: pyinstaller --onefile --noupx main.py

main.py

from OpenGL import GL

print("Hello, OpenGL")

I got this error: ImportError: cannot import name 'opengl_arrays_modules' from 'PyInstaller.utils.hooks'

Full log:

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)
8Observer8
  • 868
  • 10
  • 17

3 Answers3

5

Using python 3.8.5:

I tried to upgrade the hooks :

pip install -U pyinstaller-hooks-contrib 

to upgrade the hooks, it replies with

Requirement already up-to-date: pyinstaller-hooks-contrib in c:\python38\lib\site-packages (2020.7)

I removed the pip version :

pip uninstall pyinstaller-hooks-contrib 

So, I had to update with the repository files:

git clone https://github.com/pyinstaller/pyinstaller-hooks-contrib.git
cd pyinstaller-hooks-contrib
python setup.py install

I have now 2020.8 version setted up and the inital problem is solved

sancelot
  • 1,905
  • 12
  • 31
  • 1
    I made as you wrote. I built my example using the command `pyinstaller --onefile --windowed --noupx main.py` When I tried to run `main.exe` I got the error: `Fatal error detected. Failed to execute script pyi_rth_pkgres`. But I found that I can use addition key and it works: `pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --windowed --noupx main.py` – 8Observer8 Aug 26 '20 at 17:29
  • This worked perfectly for me. I wonder why they haven't uploaded the 2020.8 version to Pypi yet. – vikarjramun Aug 27 '20 at 21:08
  • @8Observer8 please give your references, and which python versin you are using . https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages – sancelot Sep 02 '20 at 06:55
  • @sancelot I am using 3.7.8 – 8Observer8 Sep 02 '20 at 10:59
  • Nice simple fix. Thanks! – Magnus Sep 10 '20 at 21:33
3

Pyinstaller developpers have recently made changes in the hooks. The one for OpenGL has been moved to https://github.com/pyinstaller/pyinstaller-hooks-contrib . I believe you still have the old hook from a previous installation of pyinstaller. This one will not work since they also made changes in the code. You should delete the OpeenGL hook (C:\Users\8Observer8\AppData\Roaming\Python\Python37\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-OpenGL.py) or remove pyinstaller and install it again. Then get the contrib form github and point to it with --additional-hooks-dir

Eric Mathieu
  • 631
  • 6
  • 11
  • 2
    Thank you very much. It works. My steps: (1) I deleted the `hook-OpenGL.py` file, (2) `pip uninstall pyinstaller`, (3) pip install pyinstaller, (4) I added a new key to PyInstaller `--hidden-import=pkg_resources.py2_warn` because I had the runtime error `Failed to execute script pyi_rth_pkgres`. Now command look like this: `pyinstaller --hidden-import=pkg_resources.py2_warn --onefile --windowed --noupx main.py` It works with OpenGL from PySDL2 and PySide2 – 8Observer8 Jul 23 '20 at 13:01
0

It doesn't work with wxPython. I did all of this. I saw that

It works with OpenGL from PySDL2 and PySide2

  • Try this sequence of commands: (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` – 8Observer8 Aug 26 '20 at 17:34