[vtkusers] Python 3 requires relative or correct absolute imports

David Gobbi david.gobbi at gmail.com
Mon Oct 5 10:17:46 EDT 2015


On Mon, Oct 5, 2015 at 6:56 AM, Matthias Blaicher <matthias at blaicher.com>
wrote:

> Hi,
>
> in my quest to have a working PKGBUILD for Arch Linux with Python 3
> support I've stumbled over a new issue:
>
> > Python 3.5.0 (default, Sep 20 2015, 11:28:25)
> > [GCC 5.2.0] on linux
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> import vtk
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "/usr/lib/python3.5/site-packages/vtk/__init__.py", line 39, in
> <module>
> >     from .vtkCommonCore import *
> >   File "/usr/lib/python3.5/site-packages/vtk/vtkCommonCore.py", line 1,
> in <module>
> >     from vtkCommonCorePython import *
> > ImportError: No module named 'vtkCommonCorePython'
> >>>>
>
> It's clear that this fails, since /usr/lib/python3.5/site-packages/vtk/
> is not in the search path, so it cannot find
> /usr/lib/python3.5/site-packages/vtk/vtkCommonCorePython.so.
>
> This can be confirmed by adding the vtk package to the search path via
> > export PYTHONPATH=/usr/lib/python3.5/site-packages/vtk
>
> However, this should obviously work without manually defining the search
> path. I propose to change the line to
>
> > from vtk.vtkCommonCorePython import *
> or
> > from .vtkCommonCorePython import *
>

This assumes that the extension modules are installed in the same
directory as the pure-python modules, which (for me at least) is
generally not the case.  Often the extension modules are kept in
a platform-specific directory somewhere else in the path.

Tonight I can look at the PEPs for this.

 - David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151005/bf084417/attachment.html>


More information about the vtkusers mailing list