I’m after advice on the current recommended route for creating a local library for which the
classes can be wrapped [Python]
Previously releases provided an
Examples/Build/vtkLocal directory that could be used as a template for local libraries.
This seems to have been deprecated at least its not in the git archive.
The replacement Examples/Build/vtkMy provides scaffolding for a local library
but des not seem to support wrapping, at least not via Python. The classes in the
example library are used via C++. Am I missing something, or is there an
example somewhere of a local library with wrapped classes that I could follow?
I’ve nothing against going back to 1st principles and starting again from CMake
but there used to be a good solution and if the problem is already solved
its unnecessarily wasteful.
The new example is here. In VTK 9, the wrapping of local libraries is more-or-less automated (more so than before), but the local libraries must be structured as a VTK module.
In the example, the important pieces are:
A subdirectory (the module, any name can be used) with a vtk.module file
A CMakeLists.txt file with vtk_module_wrap_python to wrap the module
Thanks David, Exactly what I was looking for. However In trying to built the local example as included as a test
I’ve run into issues:
1.CMake Error at CMakeLists.txt:11 (include):
include could not find requested file:
/vtkExternalModuleMacros.cmake
If I look in /usr/local/libcmake/vtk that macro is indeed not present
I find it present when using 6.1, 6.3, 7.1, 9.0
If I cp the file to the 9.1 dir and rererun cmake I get
include could not find requested file:
/vtkExternalModuleMacros.cmake
made me wonder if the problem is in cmake concatenating
${VTK_CMAKE_DIR} with the filename . However
the core vtk build is fine. I’ve tried multiple versions
of Cmake.
2.from line 8 of CMakeLists
The VTK_USE_FILE is no longer used starting with 8.90
I’m using CMake 3.8.0 to satisfy the version constraint 3.8…3.12
I’m having the issues with both the VTK-9.0.1 tarball and the git head.
It’s very possible that the old Examples/Build/vtkLocal is not working anymore.
Edit: The vtkLocal example was removed from ‘master’ in March, and it’s not in the current release branch either. So it’s a dead end, it’s been superseded by the Examples/Modules examples.
Thanks. I could get the example module built and working from boththe interactive vtkpython prompt and with the example python script
inthe Testing directory.
However if I try to add my own class to the module I get
AttributeError: module ‘wrapping.vtkWrappable’ has no attribute ‘vtkGrid’
where vtkGrid is the name of the class I want to add & instantiate
I suspect Ive missed a step, I
put the .h, .cc files in the module directory
ensured the header file was including the module header, and put
the appropriate export in the class declaration
UpdateCMakeLists to add the new class.
rerun CMake, built and installed.
The example class vtkWrappable is working fine, my class is not
have I missed anything, or am I using wrong steps to
instantiate froma module?
If anyone has time to look I attach a tarball
of my directory. Th new class is vtkGrid
Testing/import_grid.py is the python script I wrote to test,
Thanks David. Not clear this is strictly the same issue however I didn’t think it
worth creating a new thread
I’m running into a different problem now. Trying to build the
Examples/Modules/Wrappable from VTK9.1
Attempting to ccmake I get
but it set VTK_FOUND to FALSE so package “VTK” is considered to be NOT
FOUND. Reason given by package:
Could not find the VTK package with the following required components:
Python.
CMake Warning at CMakeLists.txt:10 (find_package):
Found package configuration file:
Skipping example: Could not find the VTK package with the following required components: Python.
VTK is built and installed and python scripts are working . Paths appear to be okay.
Any thoughts on what might trigger this error might help me track down the issue.
You haven’t given me much information to work with. Is your installed VTK one that you built yourself? What are the details of its configuration, e.g. BUILD_SHARED_LIBS, which version of Python, is there anything special about your environment?
I just ran a check on my own system (ubuntu 20.04, VTK 9.1, using ubuntu’s python 3.8) and Examples/Modules/Wrappable built just fine. My VTK was built with BUILD_SHARED_LIBS=ON and VTK_WRAP_PYTHON=ON and I used “make install” to do the installation.
When I configured the Wrappable example, I set VTK_DIR=<install-prefix>/lib/cmake/vtk-9.1 (the VTK_DIR should be set to the directory where vtk-config.cmake is located).
Hi David,
Sorry - I tried to do a clean build and think I found the problem.
When I try to run ccmake in the dir for the example Wrappable example I get
Parse error. Expected “(”, got newline with text "
I’ve looked at the CMake file with vi and od but can’t see
why its generating this error, would you check the attached please.
Although given the above they may be moot To answer your Qs from your reply post.
I’m using my own build of VTK9.1 I’m on OSX 11.6.1
CMake usually gives a line number when it reports a syntax error, like the following:
CMake Error at CMakeLists.txt:27:
Parse error. Expected "(", got newline with text "
As for the error, it’s not in your main CMakeLists.txt, so maybe it’s in a CMakeLists.txt in a subdirectory?
That particular error means you have a stray word somewhere in the CMakeLists.txt that is neither followed by nor within parentheses. Valid cmake syntax:
Apols for the delay in replying I tried diging deeper. I never isolated the location of the parse error but doing a build with a fresh copy cleared the error.
however I’m now stuck with
from wrapping import vtkWrappable
wrap = vtkWrappable()
wrap = vtkWrappable()
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘module’ object is not callable
I looked in /usr/local/lib/python3.10/site-packages: