tensorflow / lucid

A collection of infrastructure and tools for research in neural network interpretability.
Apache License 2.0
4.64k stars 652 forks source link

Bug: AttributeError: module 'ctypes' has no attribute 'util' in glcontext.py, Line 58 #286

Open ChepeAicrag opened 3 years ago

ChepeAicrag commented 3 years ago

Describe the bug

I am working in colab, and I am following the tutorial from Using OpenGL with Colab Cloud GPUs. It is important to mention that the version used is Python 3.7.10.

When at the time of import

from lucid.misc.gl.glcontext import create_opengl_context

I get this traceback:

----> 1 from lucid.misc.gl.glcontext import create_opengl_context
      2 
      3 # Now it's safe to import OpenGL and EGL functions
      4 import OpenGL.GL as gl
      5 

/usr/local/lib/python3.7/dist-packages/lucid/misc/gl/glcontext.py in <module>()
     56 # [2] https://devblogs.nvidia.com/linking-opengl-server-side-rendering/
     57 # [3] https://bugs.python.org/issue9998
---> 58 _find_library_old = ctypes.util.find_library
     59 try:
     60 

AttributeError: module 'ctypes' has no attribute 'util'

Solution

The reason for this is that import ctypes does not import ctypes.util by default anymore in newest python. Therefore after import ctypes there should be an extra line import ctypes.util.

Now the imports in the file glcontext.py with the import added, it would be as follows:

import ctypes
import ctypes.util
from ctypes import pointer
import os

Or also import the other way:

import ctypes
from ctypes import pointer, util
import os

And with that import will correct the problem.

zzj-eric commented 2 years ago

Hello, when i do as you said, i get a new problom. Unable to load OpenGL libraries. Make sure you use GPU-enabled backend. Press "Runtime->Change runtime type" and set "Hardware accelerator" to GPU. ImportError: 'Unable to load EGL library' None, 126, None, 'libEGL.so', 'libEGL.so' Do you know how to solve it?