Reputation: 25
I am working with a group of people using Ubuntu 16.04 with Python 3.7.3 running Anaconda 2019.03. For a new project I was trying to use VTK and the version installed was 8.2.0. Running the example from here: https://lorensen.github.io/VTKExamples/site/Python/IO/ReadSTL/ produces an error "module 'vtk' has no attribute 'vtkSTLReader'". In further investigation the vtk module only has 9 functions and attributes missing all the ones I am used to.
I moved to another machine where I was easily able to run the example. That machines was ubuntu 20.04 with Anaconda installed with python 3.65 and VTK 8.1.1. I updated anaconda with
conda update conda
conda update --all
This resulted in vtk getting updated to VTK 8.2.0 however now if I simply run a simple python code
import vtk
vtk.
The same thing happened as the work computer. The auto complete after typing period no longer gives a list of all the functions and attributes. And trying to run old code that worked gives errors that the functions and attributes are not available in vtk. I uninstalled vtk from conda and installedthe latest VTK version 9.0.1 using pip and the error is the same. Are there dependencies that don't get updated by conda when you update vtk? Other things that I tested still work so it just seems like VTK broke. I looked through the API changes between vtk8.1.1 and 8.2.0 and although there are a few it doesn't change some of the ones that are missing like vtkRenderer() or vtkSTLReader().
I was able to go back to vtk8.1.1 and verify it works but I would really like to use vtk 8.2 or greater because there are a group of people using python 3.7 and it would be impractical to have them all move back to Python 3.65 for this.
I am basing the need for VTK >8.2 based on a post I read where python3.7 needs vtk >8.2.
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 assume I have a mismatch with something simple but just not sure what. I would appreciate if anyone has any insight into if I need to update something else in addition to the conda update.
Adding a little more detail: I tried pip install python-vtk as well. This installs python-vtk 0.1.0 and replaces vtk with version 8.1.2 with the same error messages. Moving back to python 3.65 and vtk 8.1.1 fixes the problem but I haven't been able to get any version to work with Python 3.7.
Update:
I asked for information through VTK as well.
https://discourse.vtk.org/t/installing-vtk-8-2-for-python-3-7-3-no-attributes-available/3821/4
I add a debug command in the vtk.py file. If I call the import vtk from a editor in spyder the debug does not get printed, but if I call the import vtk from the console in spyder it does. I have no idea why those two would be different.
Thanks
Upvotes: 0
Views: 685
Reputation: 25
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.
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
Upvotes: 0