无法导入OpenGL.GL

时间:2018-09-17 15:18:57

标签: python virtualenv pyopengl

设置

我在WSL中使用Python 2.7.15rc1。我已经为我的项目设置了virtualenv环境。该项目需要3个外部软件包:numpy,Pillow和PyOpenGL。这是我的

的起始代码段
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)

当然,如果不安装任何外部软件包,则代码不会运行。所以我安装了它们:

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

问题

我遇到了PyOpenGL(except)的Error: PyOpenGL has not been installed.块。

我打开了Python REPL并尝试了此操作:

import numpy->有效

import Pillow->有效

import OpenGL->有效

from OpenGL.GL import *->失败

对于失败的那个,我得到了:

>>> 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)

有什么想法吗?

0 个答案:

没有答案