33

I am running Anaconda Python 2.7 on a Win7 x64 machine and used

pip install PyOpenGL PyOpenGL_accelerate

at the Anaconda command line to install PyOpenGL.

I have some code (not my own I must confess) that makes use of glutInit

import sys
import math
import numpy

import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *

import Image

import linkage

# ... a whole load of definitions etc ...

glutInit(sys.argv)
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(600, 600)
glutCreateWindow('linkage')
init()
initWindow()
glutIdleFunc(idle)
glutMainLoop()

I run by entering the following at the command line:

python main.py peaucellier.txt

But then get the following error (line 371 is the glutInt(sys.argv) line above)

File "C:/Users/Owner/Documents/Python Scripts/linkage/main.py", line 371, in <module>
glutInit(sys.argv)

File "C:\Anaconda\lib\site-packages\OpenGL\GLUT\special.py", line 333, in glutInit
_base_glutInit( ctypes.byref(count), holder )

File "C:\Anaconda\lib\site-packages\OpenGL\platform\baseplatform.py", line 407, in __call__
self.__name__, self.__name__,

NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

I have looked at similar errors posted in this forum but none of the proposed fixes are working which is why I'm asking, what's wrong here?

Is the installation at fault? Are the imports correct?

EDIT: After trying many many fixes for the official release I am now using an unofficial release that works perfectly from Unofficial Windows Binaries for Python Extension Packages

Joyanta J. Mondal
  • 888
  • 1
  • 8
  • 20
DrBwts
  • 3,470
  • 6
  • 38
  • 62

14 Answers14

27

According to the link below the problem was with the glut installation rather than pip install. It seems glut files are not part of PyOpenGL or PyOpenGL_accelerate package. You have to download them seperately.

https://stackoverflow.com/a/39181193/7030177

Windows user can use the link below to download glut as mentioned in the given link. ftp://ftp.sgi.com/opengl/glut/glut3.html.old#windows

Linux Users can just install glut using the following command:

sudo apt-get install freeglut3-dev

Hope this helps :)

Community
  • 1
  • 1
  • 2
    Under GNU/Linux installing freeglut3 is sufficient. – wedesoft Jun 14 '19 at 15:49
  • 3
    The FTP link is no longer hosted. – KareemElashmawy Jul 05 '19 at 22:08
  • 'sudo apt-get install freeglut3-dev' saved my day! – Tai Christian Oct 31 '19 at 16:56
  • 1
    On my windows PyOpenGL work fine with copy of freeglut.dll with name freeglut32.vc14. – Alexey Oct 07 '20 at 13:51
  • As @Alexey noted, just rename freeglut.dll to freeglut64.vc14 (if you have a 32-bit interpreter, rename to freeglut32.vc14). The original freeglut.dll must be of the correct bit size. Then placed them to your python file. The numerical ending of the file extension probably [depends](https://wiki.python.org/moin/WindowsCompilers) on the used interpreter version. – Artem Oct 24 '20 at 12:59
  • Well, after python update to version 3.8.6, solution above didn't work. So I just installed an unofficial whl package. One thing this package differs from official is DLLS folder at /Lib/site-package/OpenGL that contains freeglut64.vc15.dll. I tested this in new venv by install official package and creating the folder and coping freeglut.dll renamed to freeglut64.vc14.dll (I builded freeglut with VS2019). – Artem Nov 05 '20 at 11:01
15

After looking around for a solution to a similar problem I ran across this google group that answers the question: https://groups.google.com/forum/#!topic/glumpy-users/aC1NjEHXtEE

There is a problem with OpenGL.GLUT when downloaded as pip from the official source. Uninstall OpenGL using pip, then download OpenGL from http://www.lfd.uci.edu/~gohlke/pythonlibs/

A. Rodas
  • 20,171
  • 8
  • 62
  • 72
user2723240
  • 803
  • 1
  • 13
  • 23
9

For people on Linux with this error after installing via easy_install PyOpenGL or pip install PyOpenGL.

-> Install the distribution package as: sudo apt-get install python-opengl - this works for me.

pds
  • 2,242
  • 1
  • 22
  • 20
7

If installing PyOpenGL from easy_install, pip or conda, make sure that you have already installed a GLUT implementation, such as FreeGLUT (prebuilt Windows binaries).

For FreeGLUT, copy the distributed files to a location on your hard drive and then add the path to the bin directory (which contains the GLUT DLLs) to your PATH environment variable. Then PyOpenGL should work as expected.

Gnat
  • 2,861
  • 1
  • 21
  • 30
6

It is mainly because you're running 64-bit windows put pip is installing 32-bit version of PyOpenGL.

To fix this, follow these steps:

  1. Uninstall existing PyOpenGL, Run pip uninstall PyOpenGL PyOpenGL_accelerate

  2. Download the 64-bit builds of PyOpenGL and PyOpenGL accelerate from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

  3. How to choose which one to download? Well, first you need to check your python version. Run python --version to determine. Then according to your version download the whl files for PyOpenGL and PyOpenGL accelerate. For example, if you have Python 3.8, download these 2 files:

PyOpenGL‑3.1.5‑cp38‑cp38‑win_amd64.whl

PyOpenGL_accelerate‑3.1.5‑cp38‑cp38‑win_amd64.whl

Similarly, if you run Python 3.9, download these instead:

PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl

PyOpenGL_accelerate‑3.1.5‑cp39‑cp39‑win_amd64.whl

Note: Must download amd64 ones, after all, you're running 64-bit windows.

  1. Now go to the folder where you downloaded the files and run powershell/cmd with administrator there.

  2. Use pip to force install those files. For example:

pip install PyOpenGL-3.1.5-cp38-cp38-win_amd64.whl --force-reinstall

pip install PyOpenGL_accelerate-3.1.5-cp38-cp38-win_amd64.whl --force-reinstall

Note: Install PyOpenGL first and then PyOpenGL_accelerate

  1. If the installation succeeds, you may be able now to run.

Some facts to make sure:

*All platforms must be of the same bit version.

*System type, python, OpenGL needs to be of the same bit version. In my case it was x64 bit

*It is necessary to restart your desktop if you reinstall any one of them (Python, OpenGL)

*It is recommended to keep your pip version at 20.3, I downgraded it from 21.1.3

Joyanta J. Mondal
  • 888
  • 1
  • 8
  • 20
3

I got the same error and a solved installing required files from here.

Download these files:

  • PyOpenGL-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )

  • PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )

  • PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl (download if your computer 32 bits )

  • PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl (download if your computer 64 bits )

install these .whl files for 64 bits:

pip install PyOpenGL-3.1.1-cp27-cp27m-win_amd64.whl
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win_amd64.whl

install these .whl files for 32 bits:

pip install PyOpenGL-3.1.1-cp27-cp27m-win32.whl 
pip install PyOpenGL_accelerate-3.1.1-cp27-cp27m-win32.whl
Harun ERGUL
  • 5,770
  • 5
  • 53
  • 62
  • ergul, you will notice that this is the same link as in the opening post. – DrBwts Mar 29 '16 at 18:44
  • @DrBwts you are right. This question asked by you 2 years ago. I just write a solution with step by step for people who don't know english very well. – Harun ERGUL Mar 30 '16 at 07:51
3

for python 2.7, PyopenGL needs vc++ 9 compiler, download and install it.

then:

python -m pip install --upgrade pip

pip install image

pip install numpy

pip install PyOpenGL PyOpenGL_accelerate

I downloaded freeglut

unzipped it and added bin directory to the path when calling: glutCreateWindow("sometitle") changed to glutCreateWindow(b'sometitle')

and got it run on windows 7

Szabolcs Dombi
  • 5,493
  • 3
  • 39
  • 71
1

My case is different, Python 3.6 and windows 10. However exactly same error message. Tried all above solutions, no success. Downloaded WHL file right to my computer and version of python from HERE

Then pip installs filename.Whl, no more issue!

The answer was from a Chinese website: Answer Link

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
Mars Carl
  • 56
  • 1
1

Yes, this happened to me on Windows 10 running python 2.713 anaconda 4 64 bit. I had used conda to install pyopengl but received the same error as above. So I downloaded freeglut from transmissionzero and just copied the freeglut.dll (64 bit for me) to the same directory as my source file (it just needs to be in the dll searchpath) and all was good.

rhoids
  • 19
  • 2
0

I know it is a little late. I also encountered this problem with python 2.7 (32 bits) in windows. I tried the method mentioned by user2723240 but still failed. Finally, I solved this problem by copying glue32.dll to System32 in C drive and copy glue32.dll into my source file directory. It works well now.

ccy
  • 1,735
  • 16
  • 19
  • Yes I tried that but it it didn't work on my set up. Only the unofficial releases linked to in the OP work for me. – DrBwts Apr 10 '15 at 14:08
0

On linux, the pyopengl module attempts to use ctypes module to load the glut library as simply 'glut'. According to ctypes documentation the loadLibrary routine must be given the complete filename. Therefore, I made a symbolic link to libglut.so and named it 'glut' and everything just worked.

Travis
  • 552
  • 1
  • 8
  • 14
0

The following command should work for Anaconda users:

conda install -c conda-forge freeglut

https://anaconda.org/conda-forge/freeglut

rogererens
  • 80
  • 4
Nirmal
  • 1,285
  • 2
  • 13
  • 23
0

On windows, although PyOpenGL says it installs freeglut by default, it does not.

To patch it, you must download or compile freeglut (other answers here contain the appropriate links) and place it in a new site-packages/OpenGL/DLLS folder inside to your existing OpenGL site-packages installation.

Once there, the freeglut.dll needs to have the bits and the MSVC version appended to the filename. OpenGL/platform/win32.py has the details on exactly how it's detected.

To make it clearer the filename needs to be the one printed from the following script:

import sys
import platform

if sys.hexversion < 0x2070000:
    vc = 'vc7'
elif sys.hexversion >= 0x3050000:
    vc = 'vc14'
elif sys.hexversion >= 0x3030000:
    vc = 'vc10'
else:
    vc = 'vc9'

size = platform.architecture()[0].strip('bits')

print(f'freeglut{size}.{vc}.dll')
Tom Whittock
  • 4,081
  • 19
  • 24
0

Step 1 Install python in your system windows 10/11 preferred. for python 3.8.0 : https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe

If you have already installed then check for your python version

Open terminal and type "python --version"

it will display your python version. for example I have installed python 3.8.0.

Step 2 Next open terminal and run the below command

python -m pip install --upgrade pip==20.3

sometimes you have higher version of pip installed but its okay to downgrade back to version 20.3

Step 3 now for installing OpenGL go to this site : https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl

and download

PyOpenGL‑3.1.6‑cp38‑cp38‑win_amd64.whl (for 64bit windows) or PyOpenGL‑3.1.6‑cp38‑cp38‑win32.whl (for 32 bit) and PyOpenGL_accelerate‑3.1.6‑cp38‑cp38‑win_amd64.whl (for windows 64bit) or PyOpenGL_accelerate‑3.1.6‑cp38‑cp38‑win32.whl (for windows 32bit) Note : I have in installed python 3.8.0. so I downloaded PyOpenGL having cp38 word in it. If you have installed python 3.9 or other version download the above mentioned file having name cp39,cp10 etc.

after downloading both files according to your python version. put it a folder.

Step 4 then open terminal from that folder. Windows 10 lets you launch Command Prompt in a folder through the File Explorer's address bar. Type “cmd” in the address bar and then hit Enter

after opening terminal enter the below command

pip install PyOpenGL-3.1.6-cp38-cp38-win_amd64.whl --force-reinstall

then after installing it run the below command

pip install PyOpenGL_accelerate-3.1.6-cp38-cp38-win_amd64.whl --force-reinstall

Note : Don't forget to change the file name ( e.g. : PyOpenGL-3.1.6-cp38-cp38-win_amd64.whl) to the file name that you have downloaded.

ZIYAD K
  • 1
  • 1