Using VTK in pymatgen


(Paulfons) #1

I have installed python(3) using homebrew as well as virtualenv and virtualenvwrapper. I then made a virtualenv using “mkvirtualenv pymatgen” as the goal is run the Materials Project pymatgen libraries. After installing pymatgen and other related libraries (such as matplotlib, numpy, ipython notebook), I confirmed that all the libraries are accessible and work fine. As the pymatgen libraries require vtk for graphical output, I then installed vtk using homebrew using the command “brew install --HEAD vtk” without errors. After starting ipython, I then tried to load the vtk libraries with “import vtk”, however, an error “ModuleNotFoundError: No module named ‘vtk’” results. What should I do to access the vtk library within my ipython environment. After the successful install of vtk via homebrew, the following information appears:
Warning: vtk dependency gcc was built with a different C++ standard

library (libstdc++ from clang). This may cause problems at runtime.

==> Caveats

Even without the --with-qt option, you can display native VTK render windows

from python. Alternatively, you can integrate the RenderWindowInteractor

in PyQt5, Tk or Wx at runtime. Read more:

import vtk.qt5; help(vtk.qt5) or import vtk.wx; help(vtk.wx)

Does this imply that it is necessary to install qt5 or wx? How can I get vtk working within my virtual environment. Here is the header from starting ipython to show version info.

(pymatgen) ~/VirtualEnv $ipython

Python 3.7.0 (default, Oct 2 2018, 09:20:07)

Type ‘copyright’, ‘credits’ or ‘license’ for more information

IPython 7.0.1 – An enhanced Interactive Python. Type ‘?’ for help.

Thanks for any help.


(Sean Molenaar) #2

So, first of. Unless you really need the latest bleading edge version of vtk to test something that isn’t released yet, brew install --HEAD vtk Isn’t a good idea. The HEAD option isn’t tested by homebrew so you’ll have to compile software yourself without any guarantee it at least works somewhere.

As for virtualenv, that creates a whole new python version so it doesn’t include anything you install with brew. You’ll have to install vtk with pip in the virtualenv if you want to use it.