PyOpenGL glutInit NullFunctionError
Asked Answered
A

14

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

Amero answered 2/11, 2014 at 15:4 Comment(0)
G
28

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://mcmap.net/q/452669/-attempt-to-call-an-undefined-function-glutinit

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

Gratulate answered 1/11, 2016 at 5:40 Comment(6)
Under GNU/Linux installing freeglut3 is sufficient.Biff
The FTP link is no longer hosted.Photoengrave
'sudo apt-get install freeglut3-dev' saved my day!Langobard
On my windows PyOpenGL work fine with copy of freeglut.dll with name freeglut32.vc14.Cryan
As @Cryan 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 on the used interpreter version.Tainataint
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).Tainataint
A
16

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/

Accommodate answered 26/3, 2015 at 17:48 Comment(2)
Worked for me on Win 7, python 2.7 anaconda, freeglut solution proposed by others like Mamuka Arabuli or Gnat don't, so try it first.Benge
Worked for Win10 Python 3.8. Copying freeglut.dll did not work.Mcqueen
B
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.

Biggerstaff answered 7/10, 2015 at 14:36 Comment(0)
M
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.

Mailer answered 19/8, 2015 at 1:4 Comment(0)
S
7

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

Steading answered 5/7, 2021 at 15:2 Comment(2)
Best answer, the only one that works for me! Thanks.Weisler
Agreed. best answer in several posts here on stackoverflow.ThanksHeterodyne
C
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
Catafalque answered 28/3, 2016 at 8:41 Comment(2)
ergul, you will notice that this is the same link as in the opening post.Amero
@Amero 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.Catafalque
V
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

Varices answered 9/5, 2016 at 6:4 Comment(0)
S
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

Sardis answered 15/7, 2017 at 3:30 Comment(0)
V
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.

Vetter answered 25/8, 2017 at 23:49 Comment(0)
S
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.

Sollars answered 10/4, 2015 at 2:6 Comment(1)
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.Amero
B
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.

Belonging answered 21/7, 2016 at 21:10 Comment(0)
B
0

The following command should work for Anaconda users:

conda install -c conda-forge freeglut

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

Barricade answered 15/2, 2018 at 14:53 Comment(0)
B
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')
Blankly answered 8/11, 2022 at 18:49 Comment(0)
N
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.

Notate answered 14/12, 2022 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.