[vtkusers] Python 3 requires relative or correct absolute imports
Matthias Blaicher
matthias at blaicher.com
Mon Oct 5 10:29:19 EDT 2015
On 10/05/2015 04:17 PM, David Gobbi wrote:
> On Mon, Oct 5, 2015 at 6:56 AM, Matthias Blaicher <matthias at blaicher.com
> <mailto: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
>
Where would you put them for a system vtk installation? For both the
python 2 and the python 3 build, by default they are installed into the
site-packages directory. It feels to me that this is a good place to put
them. It's just that the import rules changed for py3k.
However you are right that both of my proposals would break your
workflow. The only thing which comes to my mind is to separate the
extension into its own (private) package.
Best,
Matthias
More information about the vtkusers
mailing list