GLEW could not be initialized: Missing GL version - VTK under Python Windows

This is an issue that I have been having for some days and have not found a solution under various Python, VTK and OpenGl versions . I have tried many things - too many to list. I saw this under anaconda but have now given up on that to try a fresh install running Python from the command prompt. I have reduced my system to what I think is the simplest level in order to isolate the issue :

So I am running Python 3.8 with VTK 9.0.1 and PyOpenGL 3.1.5 with PyOpenGL-accelerate 3.1.5

It seems that VTK does not work with Python 3.9 yet.

Running a simple example (below) I get the following error when the command window.Render() is executed :

2020-11-06 17:14:33.758 ( 0.313s) [ ]vtkWin32OpenGLRenderWin:635 ERR| vtkWin32OpenGLRenderWindow (0000020DA5C81D40): failed to get wglChoosePixelFormatARB
2020-11-06 17:14:33.790 ( 0.345s) [ ]vtkWin32OpenGLRenderWin:713 ERR| vtkWin32OpenGLRenderWindow (0000020DA5C81D40): failed to get valid pixel format.
2020-11-06 17:14:33.802 ( 0.357s) [ ]vtkOpenGLRenderWindow.c:569 ERR| vtkWin32OpenGLRenderWindow (0000020DA5C81D40): GLEW could not be initialized: Missing GL version

This message is now very familiar to me !! but what does it mean ?
.
Is this a graphics card compatibility issue ? How can I check and what can I do to fix that ??

What can I do to move on ? What other information do I need to supply ?

Script :

import vtk
import time

cone = vtk.vtkConeSource()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cone.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.ResetCamera()
camera = renderer.GetActiveCamera()

window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)

azimuth = 0
while 1:
window.Render()
if azimuth >= 360:
azimuth = 0
azimuth += 0.1
camera.Azimuth(azimuth)

time.sleep(0.1) 

Thank in anticipation - Jerry

Yea, reduce it further to the very bare minimum. (VTK + Python wrappers)

How did you install VTK? Built from source? anaconda?

You shouldn’t need PyOpenGL or any such package to use VTK since the library comes bundled with its own OpenGL loader wrapped up in vtkglew.

Spotted the PyOpenGl thing today and uninstalled it - still same message.

VTK was installed with pip install vtk but I note now that this picked up a downloaded wheel file vtk-9.0.1-cp38-cp38-win_amd64.whl which I downloaded when trying to fix this under Anaconda. However, I think this is correct - no ?

I’ve been looking at the VTK source code and the line numbers and messages all add up to initglew() failing. Can’t find the source code for that anywhere ??

Thanks for looking !!

I’ve been looking at the VTK source code and the line numbers and messages all add up to initglew() failing. Can’t find the source code for that anywhere ??

Here

Somehow the version you’ve installed has OpenGL conflicts.
Clear pip’s, conda’s cache and try again. Anaconda often installs its own shared system libraries and this might have lead to a mix up.

Can you try to build from source? IMHO, that’s the best way

I’ll try but there must be something left buried in windows somewhere as Anaconda has been uninstalled and the remaining directories deleted before I started from scratch.

I will start again with a new user environment and try this all again. Cheers !! Then it’s a new windows installation !! hey ho !!

yep, with windows, gotta do that reinstall.

I manage my VTK stuff in a neatly sandboxed Linux system within ugly windows. Check out WSL! It’s also a breeze to setup Visual Studio to work with the sandboxed Linux environment.

Can do all kinds of memory debugging/profiling shenanigans from VS for a library running in Linux.
Best things of both worlds!

Annoyingly this is a new machine (maybe the root cause of my issues) with a fresh windows and nice fast SSD !!! I use LINUX at work but all my home machines are windows. Yet to make the change - but I guess it’s coming. The latest windows version is very buggy (doesn’t remember passwords anymore …).

Just trying to get a new user and discovered that the USER variable isn’t being written properly - so working on that. Hopefully I’ll be able to report that the issue I have is fixed AND why !!

Hi, update - vtk 9.0.1 successfully make’d and built into a folder in my appdata folder (along with python).

But python can’t find the newly built vtk … (ModuleNotFoundError: No module named ‘vtk’)

so how do I link it to Python - is there a .h file or something similar that I need to add to the path. If I try pip it automatically finds the same .whl file from the internet that fails with the above message.

Finding this difficult - to do but also to understand what is going on.

Thanks in advance.

You’ve to add the path to VTK’s site-packages to PYTHONPATH

There is no site-packages folder and there is no variable PYTHONPATH !

I followed all the instructions from this page :

https://vtk.org/Wiki/VTK/Configure_and_Build#On_Windows_5

Obviously I am doing something wrong !

There is a site-packages folder in the Python directory under Lib - should I move VTK build files there ? and which ones …

No, don’t move anything. Looks like the build did not generate wrappers.

While configuring cmake, check these 3 variables that enable python wrappers

Python3_EXECUTABLE this is automatically found
VTK_PYTHON_VERSION automatically set to match above python
VTK_WRAP_PYTHON is OFF by default. Flip it.

After the configure, generate, build, install process, a site-packages directory should be there under CMAKE_INSTALL_DIR/lib

For python on windows and its hacks, this thread and this documentation should help you.

If VTK C++ works fine for you and this is a python wrapper issue, please start a new thread :slight_smile:

Things have moved on in this investigation. I failed to build VTK from scratch as none of the above resolutions worked. My suspicion being a bad windows installation.

I have now rebuilt both my laptop a Medion Akoya win 10 Home and my desktop a DELL Optiplex 9010 with win 10 Pro.

This problem does not occur on my laptop under Python 3.8 VTK 9.01 but still persists on the DELL. All other Python programs that I am developing on the DELL are fine.

It is my conclusion that the graphics card in the DELL is incompatible with VTK. As per my original post. The graphics card is build into the motherboard and I am looking to buy an extension card replacement but it;'s a bit tight in the case for duel screen versions (another problem). I read somewhere that MESA can be used as a graphics emulator but I can’t now find where I read that.

Can anyone point me towards either a solution to this - or a workaround please.

This is all very frustrating as I am new to Python and had bought this machine to make progress ij my personal development. This issue has been very complicated to work through - including the discovery of a bug in the vtk Render() command which I have posted in GitHub separately :

Python / VTK script crashes in windows

but at least I can work on my VTK project on my laptop now.

For anyone who can help the DxDiag utility produces the following report on my system :


Display Devices

       Card name: Intel(R) HD Graphics
    Manufacturer: Intel Corporation
       Chip type: Intel(R) HD Graphics Family
        DAC type: Internal
     Device Type: Full Device (POST)
      Device Key: Enum\PCI\VEN_8086&DEV_0102&SUBSYS_052C1028&REV_09
   Device Status: 0180200A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER] 

Device Problem Code: No Problem
Driver Problem Code: Unknown
Display Memory: 1664 MB
Dedicated Memory: 32 MB
Shared Memory: 1632 MB
Current Mode: 1680 x 1050 (32 bit) (60Hz)
HDR Support: Not Supported
Display Topology: Extend
Display Color Space: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
Color Primaries: Red(0.649414,0.334961), Green(0.283203,0.605469), Blue(0.151367,0.073242), White Point(0.312500,0.329102)
Display Luminance: Min Luminance = 0.500000, Max Luminance = 270.000000, MaxFullFrameLuminance = 270.000000

Looking at the VTK documentation :
[https://vtk.org/Wiki/VTK/FAQ#What_Graphics_Cards_work_with_VTK](http://VTK graphics card compatibility)

I note that VTK should work with OpenGl versions 2.1 and above. I have checked my compatibility and see that the laptop is compatible with GL version 4.3 (this works) and that my desktop is compatible only with GL version 3.1 (this does not). So something is wrong ! Either the VTK documentation is out of date or I am still not linking to the OpenGL driver for some reason.

The clue is “GLEW could not be initialized: Missing GL version” but I can’t see the issue.