[vtkusers] Python Bindings on OSX?
Eric E. Monson
emonson at cs.duke.edu
Wed Jul 14 12:23:38 EDT 2010
Just as a bit of followup info -- when you do an install the .so files end up in the VTK egg in /Library/Python/2.6/site-packages/VTK.../vtk, and they should contain internal paths to the ...PythonD.dylib libraries if you've built with VTK_USE_RPATH: ON (on my machine they refer back to the ones in the build/bin directory). You can check them with "otool -L path/to/libvtkCommonPython.so".
If all of these internal paths are correct, and the egg has been installed in the correct place, then you shouldn't have to modify the PYTHONPATH or DYLD_LIBRARY_PATH to get "import vtk" to work. If you don't want to build with RPATH ON for some reason, then the library path env variable setting is probably necessary to find the .dylib libraries.
-Eric
On Jul 14, 2010, at 12:13 PM, David Gobbi wrote:
> I can't comment on the installation issues because I always use VTK
> in-situ instead of doing an install. For the other questions,
>
> The ".so" suffix denotes a loadable python module, and it is the
> correct suffix even though it is a shared object just like a .dylib.
> You will probably note that there is a libvtkCommonPython.so and a
> libvtkCommonPythonD.dylib. The former contains the module
> initialization code, and the latter contains most of the python
> wrapper code. The .so file must be somewhere in the PYTHONPATH and
> the .dylib must be somewhere in the DYLD_LIBRARY_PATH.
>
> The best architecture to use on 0S X 10.6 is x86_64, because that is
> the architecture that the python 2.6 executable uses when you run it
> from the command line. The i386 architecture should only be used when
> building with python 2.5 for when you want to keep binary
> compatibility with OS X 10.5.
>
> David
>
>
>
> On Wed, Jul 14, 2010 at 9:20 AM, Sensei <senseiwa at gmail.com> wrote:
>> Hi! I am trying to build VTK with python bindings (I need it for MayaVi), without any success so far.
>>
>> My VTK configuration has turned on VTK_WRAP_PYTHON and BUILD_SHARED_LIBS, while the CMAKE_OSX_ARCHITECTURES is set to i386.
>>
>> The first problem is met building it, but searching on the net I find that issuing "chmod 600 Utilities/vtktiff/tif_fax3sm.c" does the trick. And it did.
>>
>> The second problem I found was in the python installation process, since it uses /usr/local also for python:
>>
>> <shell>
>> Checking .pth file support in /usr/local/lib/python2.6/site-packages/
>> error: can't create or remove files in install directory
>>
>> The following error occurred while trying to add or remove files in the
>> installation directory:
>>
>> [Errno 2] No such file or directory: '/usr/local/lib/python2.6/site-packages/test-easy-install-57720.pth'
>>
>> The installation directory you specified (via --install-dir, --prefix, or
>> the distutils default setting) was:
>>
>> /usr/local/lib/python2.6/site-packages/
>>
>> This directory does not currently exist. Please create it and try again, or
>> choose a different installation directory (using the -d or --install-dir
>> option).
>> </shell>
>>
>> However, running "/usr/bin/python2.6 setup.py install" under VTK/Wrapping/Python (without the --prefix switch), worked for me. Or at least I thought so:
>>
>> <shell>
>> $ cd Wrapping/Python && /usr/bin/python2.6 setup.py installrunning install
>> running bdist_egg
>> running egg_info
>> creating VTK.egg-info
>> ...
>> creating 'dist/VTK-5.4.2-py2.6.egg' and adding 'build/bdist.macosx-10.6-universal/egg' to it
>> removing 'build/bdist.macosx-10.6-universal/egg' (and everything under it)
>> Processing VTK-5.4.2-py2.6.egg
>> creating /Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg
>> Extracting VTK-5.4.2-py2.6.egg to /Library/Python/2.6/site-packages
>> Adding VTK 5.4.2 to easy-install.pth file
>>
>> Installed /Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg
>> Processing dependencies for VTK==5.4.2
>> Finished processing dependencies for VTK==5.4.2
>> </shell>
>>
>> The problem is with shared libraries. Trying to start the MayaVi VTK test script, or even trying to import vtk from a python shell, I get the following problem:
>>
>> <shell>
>> $ python test_vtk.py
>> Testing if Tkinter is available...
>> OK - you have Tkinter
>> TclVersion = 8.5, TkVersion = 8.5
>> Traceback (most recent call last):
>> File "test_vtk.py", line 210, in <module>
>> test_value_error()
>> File "test_vtk.py", line 178, in test_value_error
>> import vtk
>> File "/Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/__init__.py", line 41, in <module>
>> from common import *
>> File "/Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/common.py", line 7, in <module>
>> from libvtkCommonPython import *
>> ImportError: dlopen(/Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/libvtkCommonPython.so, 10): no suitable image found. Did find:
>> /Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/libvtkCommonPython.so: mach-o, but wrong architecture
>> </shell>
>>
>> This puzzles me for two reasons. First, the suffix is .so instead of the standard .dylib (I created there some symlinks with the dylib suffix, just in case). The second is simple: the architecture seems to be ok to me, although the file type might not be so:
>>
>> <shell>
>> $ file /Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/libvtkCommonPython.so
>> /Library/Python/2.6/site-packages/VTK-5.4.2-py2.6.egg/vtk/libvtkCommonPython.so: Mach-O bundle i386
>> </shell>
>>
>> Why do I get this 'wrong architecture' error? Usually, shared libs have as file types "Mach-O universal binary", and not "bundle"...
>>
>> Can you walk me out of this?
>>
>> Thanks & cheers!
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list