I am trying to use VTK on a machine with ubuntu 16.04 and python 3.7.3 running Anaconda 2019.03. Anaconda installed vtk 8.2.0.
I import vtk and type “vtk.” and the auto field only shows 9 options but is missing many important ones.
Running the example from here: https://lorensen.github.io/VTKExamples/site/Python/IO/ReadSTL/ produces an error “module ‘vtk’ has no attribute ‘vtkSTLReader’”.
I tried updating vtk to v9. No difference
I tried pip install python-vtk which changed vtk back to 8.2.0 and still no difference.
I can run vtk 8.1.1 on a different machine with no issues with Python 3.65 but I really need to run python 3.7 on a different machine for compatibility with other people so I understand I need vtk 8.2 or greater.
Based on this article I also tried installing python-vtk7 but the package was not found for ubuntu 16.04. Setting up VTK, with python3.8 and Ubuntu 20.04
I was going to try installing VTK 9 from source to see if that fixes it but I have gone down a bit of a rabbit hole with that needing a later version of CMAKE. In trying to build CMAKE, that needs a later version of openssl (for the ccmake). So would prefer a packaged version if at all possible.
I assume I have a mismatch with something simple but just not sure what. I would appreciate if anyone has any insight or anything to try.
I completely removed my anaconda and updated to anaconda 2020.02. Then I reinstalled vtk with conda install vtk which results in version 8.2.0. The issue is still the same, the standard attributes and functions inherited from a normal class are present but nothing specific to vtk.
A strange update to this issue. When i installed the latest anaconda I accepted Kite. The default auto complete can not find the vtk.vtkSTLReader() but kite can.
From Spyder: After upgrading to 2020.02 if I type import vtk, later in code if I type vtk.vtkS it doesn’t find any options for auto complete and if I type manually and run it I get the error vtkSTLReader() is not an attribute. If I type import vtk.vtkSTLReader as reader it will enable the auto fill in after typing vtk.vtkS , but when I run it I get the same error. After the updated Anaconda distribution I am running Python 3.7.6 with VTK 8.2.0.
Running from python shell has same results.
Running conda list | grep vtk from spyder console shoes correct version and information for VTK
I found vtk.py in anaconda3/lib/python3.7/site-packages and added a few debug statements to track the function including print (sys.version_info) and a print statement for ea
spch path. When I called import vtk from the console of Spyder it printed the debug messages with no issues. Even stranger then I ran my sample program and it opened a window without any error messages. Restarted spyder and ran the program without running import from console and no debug messages were printed and I got the error message same as before.
The issue ended up being my openGL support. I had three machines. One was running VMWARE which showed the issue. One was running VNC which showed the issue. And one was running ubuntu natively (using the GPU HW ) which worked fine.
The issue when VTK stopped showing options was an issue I created during debug. I created a class module vtk.py to test stuff out and ran into a namespace issue.
I was running with VMWARE and that worked OK with python 2.x and earlier versions of VTK but when I moved to Python 3x and later versions of VTK it broke because it didn’t support the right version of OpenGL. It looks like there are couple different ways to fix it, but in my case the one I used was to use a SW implementation of OpenGL to guarantee support. This was the fastest solution. The other solution would be with a virtual GL driver which leverages the HW and is likely faster and I will likely look at in the future.
For the SW implementation of OpenGL:
sudo apt install llvm-dev # make sure SW driver that supports OPENGL3.2
export LIBGL_ALWAYS_SOFTWARE=1 # Ensures vtk uses sw opengl driver: this needs to be called from each new terminal or alternatively make persistent in bashrc