[ITK] [ITK-users] Using ITK python wrapper
Matt McCormick
matt.mccormick at kitware.com
Tue Apr 1 10:23:03 EDT 2014
Hi Nicole,
The file
C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/WrapITK.pth
should be copied to
C:/Python27/Lib/site-packages
In order to import the module, Python must be able to see the *.py
files and the _* C extensions, which are the swig C extension
interface that get imported by the *.py files, and the _* C extension
modules must be able to load the ITK DLL's that they use.
HTH,
Matt
PS. To subscribe to the lists, please go here:
http://itk.org/cgi-bin/mailman/listinfo/community
and make sure to check your inbox and spambox for the confirmation email.
On Tue, Apr 1, 2014 at 4:44 AM, Chiara Caborni <chiara.caborni at gmail.com> wrote:
> Thank you for everyone getting back to me. I have had a play with the paths,
> and carried out all your suggestions. But I still have no luck. The problem
> I have firstly with the paths is that my itk.py file is
> sys.path.append('C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release'),
> along with itkBase.py, itkConfig.py, itkLazy.py, itkTemplate.py, itkTypes.py
> and the WrapITK.path.
>
> There is no itk.py in
> sys.path.append('C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python')
> that was suggested, but what I do have is InsightToolkit.py here (amongst
> many other python files). When I import InsightToolkit.py (after adding the
> lib path), I get this error:
>
>>>> import InsightToolkit
>
> Traceback (most recent call last):
>
> File "<console>", line 1, in <module>
>
> File
> "C:\Toolkits\ITK-4.5.1\build_x64_VS2008_withLTK\Wrapping\Generators\Python\Configuration\..\InsightToolkit.py",
> line 5, in <module>
>
> from ITKPyBase import *
>
> File
> "C:\Toolkits\ITK-4.5.1\build_x64_VS2008_withLTK\Wrapping\Generators\Python\Configuration\..\ITKPyBase.py",
> line 2, in <module>
>
> itkBase.LoadModule('ITKPyBase')
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
> line 103, in LoadModule
>
> if not swigModuleName in sys.modules: module = loader.load(swigModuleName)
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
> line 214, in load
>
> return imp.load_module(name, fp, pathname, description)
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/lib\ITKPyBasePython.py",
> line 30, in <module>
>
> _ITKPyBasePython = swig_import_helper()
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/lib\ITKPyBasePython.py",
> line 22, in swig_import_helper
>
> import _ITKPyBasePython
>
> ImportError: No module named _ITKPyBasePython
>
>
> I've checked and there is an ITKPyBasePython.py in the lib folder.
>
>
> For trying the ImageType = itk.Image[itk.US, 3], the error I'm getting
>
>>>> imageType = itk.Image[itk.US, 3]
>
> Traceback (most recent call last):
>
> File "<console>", line 1, in <module>
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkLazy.py",
> line 37, in __getattribute__
>
> itkBase.LoadModule(module, namespace)
>
> File
> "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
> line 42, in LoadModule
>
> swig.__dict__.update(this_module.swig.__dict__)
>
> AttributeError: 'module' object has no attribute 'swig'
>
>
> There seems to be some issue with swig, but I don't understand how it works
> and hence why mine isn't working. Any ideas anyone?
>
>
> Cheers,
>
> Nicole
>
>
>
> 2014-03-31 14:36 GMT+01:00 Matt McCormick <matt.mccormick at kitware.com>:
>
>> Hi Chiara,
>>
>> If the file 'WrapITK.pth' from Wrapping/Generators/Python/ iin the
>> build tree is copied to the site-packages directory of your Python
>> distribution, it should help.
>>
>> Matt
>>
>> On Mon, Mar 31, 2014 at 8:07 AM, Paolo Zaffino <p.zaffino at yahoo.it> wrote:
>> > Hi,
>> > I confirm your wrong path.
>> > Anyway I usually add also:
>> >
>> > sys.path.append("YOUR_BUILD_PATH/lib")
>> > Maybe this can help.
>> >
>> > Paolo
>> > Il Lunedì 31 Marzo 2014 11:03, Michka Popoff <michkapopoff at gmail.com> ha
>> > scritto:
>> > Hi
>> >
>> > seems your path is not correctly set. The path should be :
>> >
>> > sys.path.append('C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python')
>> > There is no Release folder in the Python folder.
>> > Maybe you'll have to play a little bit with the path, you are under
>> > windows
>> > so perhaps the slashes need to be replaced by backslashes ?
>> >
>> > Michka
>> >
>> > Le 31 mars 2014 à 10:38, Chiara Caborni a écrit :
>> >
>> > Hello,
>> >
>> > I'm writing on behalf of Nicole in cc, which has subscribed to
>> > insight-users at itk.org, but still cannot send mails directly to the
>> > community, can you do something about that? thank you
>> >
>> >
>> > I'm trying to use the python wrapped ITK, but I'm running into trouble
>> > setting up my image type.
>> >
>> >
>> >
>> > My code so far:
>> >
>> > import sys
>> >
>> >
>> > sys.path.append('C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release')
>> >
>> > import itk
>> >
>> > pixelType = itk.UC
>> >
>> > imageType = itk.Image[pixelType,3]
>> >
>> >
>> >
>> > Traceback (most recent call last):
>> >
>> > File "<console>", line 1, in <module>
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkLazy.py",
>> > line 37, in __getattribute__
>> >
>> > itkBase.LoadModule(module, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 95, in LoadModule
>> >
>> > LoadModule(dep, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 95, in LoadModule
>> >
>> > LoadModule(dep, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 95, in LoadModule
>> >
>> > LoadModule(dep, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 95, in LoadModule
>> >
>> > LoadModule(dep, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 95, in LoadModule
>> >
>> > LoadModule(dep, namespace)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 103, in LoadModule
>> >
>> > if not swigModuleName in sys.modules: module =
>> > loader.load(swigModuleName)
>> >
>> > File
>> >
>> > "C:/Toolkits/ITK-4.5.1/build_x64_VS2008_withLTK/Wrapping/Generators/Python/Release\itkBase.py",
>> > line 213, in load
>> >
>> > fp, pathname, description = imp.find_module(name)
>> >
>> >
>> >
>> > Can anyone help me understand why this is happening and what I can do
>> > about
>> > it?
>> >
>> >
>> >
>> > Cheers,
>> >
>> > Nicole
>> > --
>> > Chiara
>> >
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.php
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.itk.org/mailman/listinfo/insight-users
>> >
>> >
>> >
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.php
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.itk.org/mailman/listinfo/insight-users
>> >
>> >
>> >
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.php
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.itk.org/mailman/listinfo/insight-users
>> >
>
>
>
>
> --
> Chiara
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users
More information about the Community
mailing list