4

Setup

I am using Python 2.7.15rc1 in WSL. I have set up a virtualenv environment for my project. This project requires 3 external packages: numpy, Pillow, and PyOpenGL. Here is a snippet of the starting code for my

import sys, os, numpy, math

try: # Pillow
  from PIL import Image
except:
  print 'Error: Pillow has not been installed.'
  sys.exit(0)

try: # PyOpenGL
  from OpenGL.GLUT import *
  from OpenGL.GL import *
  from OpenGL.GLU import *
except:
  print 'Error: PyOpenGL has not been installed.'
  sys.exit(0)

Of course, without installing any of the external packages, the code did not run. So I installed them with:

python -m pip install -U numpy
python -m pip install -U Pillow
python -m pip install -U PyOpenGL

Problem

I run into the except block for PyOpenGL (Error: PyOpenGL has not been installed.).

I opened up the Python REPL and tried this:

import numpy -> works

import Pillow -> works

import OpenGL -> works

from OpenGL.GL import * -> fails

For the one that fails, I get this:

>>> from OpenGL.GL import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
    from OpenGL import error as _error
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/error.py", line 12, in <module>    from OpenGL import platform, _configflags
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/__init__.py", line 35, in <module>
    _load()
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/__init__.py", line 32, in _load
    plugin.install(globals())
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 92, in install
    namespace[ name ] = getattr(self,name,None)
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 14, in __get__
    value = self.fget( obj )
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/glx.py", line 96, in GetCurrentContext
    return self.GL.glXGetCurrentContext
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 14, in __get__
    value = self.fget( obj )
  File "/mnt/c/Users/Henry/Desktop/cmpe457/a1/local/lib/python2.7/site-packages/OpenGL/platform/glx.py", line 20, in GL
    raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'GL: cannot open shared object file: No such file or directory', 'GL',
None)

Any idea what is wrong?

bitscuit
  • 976
  • 1
  • 11
  • 26

1 Answers1

0

This question is all over the internet. The answer is the imports MUST be in the correct order:

import OpenGL
import OpenGL.GLU
import OpenGL.GL

At least for python3.5 and python3-opengl version 3.0.2 if the GL import comes before the GLU import there will be a stream of error messages ending with:

AttributeError: module 'OpenGL.GL' has no attribute 'GL_READ_WRITE'.
Presumably this is just another obscure python version comparability issue.

Jan Černý
  • 1,268
  • 2
  • 17
  • 31
Brad
  • 11
  • 1
  • 1