46

I'm trying to run NeHe's tutorial here using Python 2.7.3, but It's throwing the error ImportError: No module named OpenGL.GL

So how do I fix that? This is the code:

from OpenGL.GL import *
genpfault
  • 51,148
  • 11
  • 85
  • 139
CyanPrime
  • 5,096
  • 12
  • 58
  • 79
  • 8
    Silly question. Did you install PyOpenGL? [Using OpenGL in Python](http://pyopengl.sourceforge.net/ctypes/using.html) – César Jun 26 '12 at 20:25

6 Answers6

40

Do you have PyOpenGL installed correctly? If you are having n00bie issues getting new modules set up correctly, I recommend installing setuptools. Once you have setuptools installed, you will find a program in your python27/Scripts directory called "easy_install" that you can use to get packages installed correctly.

For instance on my windows setup, I use:

C:\Python27\scripts\easy_install pyopengl

to set up PyOpenGL on my system, and then your example case works fine. I remember when I started using Python I had the same issues trying to get a working PyOpenGL set up correctly so I could run the NeHe code, and all of my issues went away when I learned about easy_install

On Linux:

sudo easy_install pyopengl

As well as:

sudo apt-get install python python-numpy python-opengl python-qt4 python-qt4-gl
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
K. Brafford
  • 3,755
  • 2
  • 26
  • 30
24

basically you need to install opengl but the library in python is called pyopengl not opengl you can use the pip install command inside anaconda prompt which can be done by the following command:

pip install pyopengl
gehbiszumeis
  • 3,525
  • 4
  • 24
  • 41
Karim Sherif
  • 442
  • 4
  • 6
10

anaconda is a great python package manager,if you have anaconda,just:

conda install pyopengl
dorbodwolf
  • 322
  • 2
  • 13
6

It means you don"t have that module,,

Install it by using any python packet manager.

For LINUX just execute either one of things down below

Debian based

for python v3.x

apt-get install python3-opengl

this is for python v2.x

apt-get install python-opengl

with easy_install

easy_install pyopengl

with conda pakage manager

conda install pyopengl

by python itself

python -m pip install pyopengl

for WINDOWS:

run the easy_installer in command prompt located in root directory of python, where u have installed

ex: D:\Python36\scripts\easy_install pyopengl

For apple computer

brew install pyopengl
Denim Datta
  • 3,740
  • 3
  • 27
  • 53
ravish
  • 61
  • 1
  • 3
0

I am using openSUSE Linux Tumbleweed and had the same error (yes I have installed python3-opengl [via zypper package manager] and PyOpenGL [via pip]).

Solved the problem by using python3 explicitly to run command, because it seems that the installation is done for the newes version of python. The normal python command runs older python 2.

In short:

python opengl_test.py    # Does NOT work
python3 opengl_test.py   # Works
-2

Edit:found the answer: from the upper menu go to File >> Settings >> Project: projectname from there select the suitable interpreter path.

Note: somehow by default it was set to "venv" folder path which my PyOpenGL is not installed. through the dropdown, I selected the "python" folder.

danmecha
  • 1
  • 1
  • 1
    In case someone stumbles across this and is wondering why it got downvotes, this is curving best practices in suggesting that OP should not be using a virtual environment and instead be using their global environment, something that is not recommended in almost all cases when working with Python. What this responder should have done was install the corresponding packages in their virtual environment for the project ("venv" folder path) and leave the interpreter path as-is. – crock May 25 '22 at 17:24