[vtkusers] from vtk import * ImportError: (Python VTK 6.2 on ubuntu 14.04)

Manjunath K E ke.manjunath at gmail.com
Mon Aug 10 11:11:59 EDT 2015


>
> Hi Dan Lipsa,
>
>
> I checked out vtk 6.2 as per the instructions in
> https://gitlab.kitware.com/vtk/vtk/blob/master/Documentation/dev/git/download.md
>
> I rebuilt VTK and when I try to run the following code, the problem of
> GetRange() still persists.
>
> >>> from vtk import *
> >>> reader = vtkNetCDFCFReader()
> >>> reader.SetFileName("3d.nc")
> >>> reader.SphericalCoordinatesOff()
> >>> reader.SetReplaceFillValueWithNan(1)
> >>> reader.Update()
> >>>
> reader.GetOutput().GetPointData().SetScalars(reader.GetOutput().GetPointData().GetArray("SAL"))
> 0
> >>> reader.UpdateMetaData()
> 1
> >>> reader.Update()
> >>> reader.UpdateInformation()
> >>> reader.GetOutput().GetPointData().GetScalars().GetRange()
> (nan, nan)
>
> Although the range is (28.04-36.88), but I get (nan, nan). Please help me.
>
>  Thanks and Regards,
>  Manjunath K E
>
> ---------- Forwarded message ----------
> From: Dan Lipsa <dan.lipsa at kitware.com>
> Date: Wed, Aug 5, 2015 at 8:06 PM
> Subject: Re: [vtkusers] from vtk import * ImportError: (Python VTK 6.2 on
> ubuntu 14.04)
> To: Manjunath K E <ke.manjunath at gmail.com>, VTK Users <vtkusers at vtk.org>
>
>
> Manjunath,
> I get a range rather than NaN when I run it on my machine with the latest
> VTK from git master.
>
> Range of SAL: 28.04-36.88
>
> I do have error complaining about missing
> sliceOn.jpg and sliceOff.jpg.
>
> Could you try your example on the latest VTK master (your have to build
> it)
>
>
> http://www.vtk.org/Wiki/VTK/Configure_and_Build
>
> or on VTK 6.3 rc1?
> http://www.vtk.org/download/
>
> I am not sure what your other python error is, maybe related to
>
> http://stackoverflow.com/questions/15608236/eclipse-and-google-app-engine-importerror-no-module-named-sysconfigdata-nd-u
>
>
> On Wed, Aug 5, 2015 at 9:41 AM, Manjunath K E <ke.manjunath at gmail.com>
> wrote:
>
>> Hi Dan Lipsa,
>>
>> Please find the required file "3d.nc" and the python code  is  attached
>> in "datareader.py1".
>>
>> The problem is that the *a,b = reader.GetOutput().*
>> *GetPointData().GetScalars().**GetRange() *is returning NaN value.
>>
>> one more thing I found was, when I start *"vtkpython**"* by keeping *"*
>> */usr/lib/python2.7**" *in *"PYTHONPATH**" *then following error will be
>> obtained. If I remove *"**/usr/lib/python2.7" *from *"PYTHONPATH**"*, I
>> wont get any error.
>>
>> export
>> PYTHONPATH=/usr/lib/python2.7:/usr/local/lib/python2.7/site-packages:$PYTHONPATH
>>
>> manju at iiitb-gvcl-Z800:~/manju/academics/iiitb/project/codes/incois__laptp/src_vtk6$
>> vtkpython
>> vtk version 6.2.0
>> Traceback (most recent call last):
>>   File "/usr/lib/python2.7/site.py", line 563, in <module>
>>     main()
>>   File "/usr/lib/python2.7/site.py", line 545, in main
>>     known_paths = addusersitepackages(known_paths)
>>   File "/usr/lib/python2.7/site.py", line 272, in addusersitepackages
>>     user_site = getusersitepackages()
>>   File "/usr/lib/python2.7/site.py", line 247, in getusersitepackages
>>     user_base = getuserbase() # this will also set USER_BASE
>>   File "/usr/lib/python2.7/site.py", line 237, in getuserbase
>>     USER_BASE = get_config_var('userbase')
>>   File "/usr/lib/python2.7/sysconfig.py", line 578, in get_config_var
>>     return get_config_vars().get(name)
>>   File "/usr/lib/python2.7/sysconfig.py", line 524, in get_config_vars
>>     _init_posix(_CONFIG_VARS)
>>   File "/usr/lib/python2.7/sysconfig.py", line 408, in _init_posix
>>     from _sysconfigdata import build_time_vars
>>   File "/usr/lib/python2.7/_sysconfigdata.py", line 6, in <module>
>>     from _sysconfigdata_nd import *
>> ImportError: No module named _sysconfigdata_nd
>>
>>
>>  Thanks and Regards,
>>
>>  Manjunath K E
>>  Help Ever Hurt Never
>>
>>
>> On Tue, Aug 4, 2015 at 10:15 PM, Dan Lipsa <dan.lipsa at kitware.com> wrote:
>>
>>> It would be great if you could share your data as well so that I can
>>> check it with my installation. Thanks,
>>> Dan
>>>
>>>
>>> On Tue, Aug 4, 2015 at 11:31 AM Manjunath K E <ke.manjunath at gmail.com>
>>> wrote:
>>>
>>>> Hi Dan Lipsa,
>>>>
>>>> Thanks for the reply. The error is occurring during runtime. There was
>>>> no error, when i ran it in interpreter. All the lines in the script
>>>> executed smoothly.
>>>> I have tested the same code using vtk 6.0.0 there was no error.
>>>>
>>>> Also, the output that i get is not proper. There is problem in the
>>>> color map of the output produced. The scale bar is not displayed properly.
>>>> ==========================================
>>>> #!/usr/bin/env python
>>>> from vtk import *
>>>>
>>>> reader = vtkNetCDFCFReader()
>>>> reader.SetFileName("3d.nc")
>>>> reader.SphericalCoordinatesOff()
>>>> reader.SetOutputType(6)
>>>> reader.SetReplaceFillValueWithNan(1)
>>>> reader.Update()
>>>> #Copy SAL Array to scalar value field of point data ..this makes point
>>>> data to point to SAL array
>>>>
>>>> reader.GetOutput().GetPointData().SetScalars(reader.GetOutput().GetPointData().GetArray("SAL"))
>>>> reader.UpdateMetaData()
>>>> reader.Update()
>>>> reader.UpdateInformation()
>>>> output = reader.GetOutput()
>>>>
>>>> a,b = reader.GetOutput().GetPointData().GetScalars().GetRange()
>>>> lut = vtk.vtkColorTransferFunction()
>>>> lut.AddRGBPoint(a,         0.0, 0.0, 0.8)
>>>> lut.AddRGBPoint(a+(b-a)/4, 0.0, 0.5, 0.5)
>>>> lut.AddRGBPoint(a+(b-a)/2, 0.0, 1.0, 0.0)
>>>> lut.AddRGBPoint(b-(b-a)/4, 0.5, 0.5, 0.0)
>>>> lut.AddRGBPoint(b,         1.0, 0.0, 0.0)
>>>> lut.SetNanColor(0,0,1)
>>>>
>>>> # the mapper that will use the lookup table
>>>> mapper = vtkDataSetMapper()
>>>> mapper.SetInputData(reader.GetOutput())
>>>> mapper.SetScalarModeToUsePointData()
>>>> mapper.SetLookupTable(lut)
>>>> mapper.SetScalarRange(a,b)
>>>> # the actor
>>>> gridActor = vtkActor()
>>>> gridActor.SetMapper( mapper )
>>>> scaleBarActor = vtkScalarBarActor()
>>>> scaleBarActor.SetLookupTable( mapper.GetLookupTable() )
>>>> scaleBarActor.SetTitle("Color Map for Point Data")
>>>> scaleBarActor.SetOrientationToHorizontal()
>>>> scaleBarActor.GetLabelTextProperty().SetColor(0,0,1)
>>>> scaleBarActor.GetTitleTextProperty().SetColor(0,0,1)
>>>>
>>>> # position it in window
>>>> coord = scaleBarActor.GetPositionCoordinate()
>>>> coord.SetCoordinateSystemToNormalizedViewport()
>>>> coord.SetValue(0.1,0.05)
>>>> scaleBarActor.SetWidth(.5)
>>>> scaleBarActor.SetHeight(.1)
>>>>
>>>> # renderer and render window
>>>> renderer = vtkRenderer()
>>>> renderer.SetBackground(1, 1, 1)
>>>> renderer.SetGradientBackground(1) # Set background to white
>>>> renWindow = vtk.vtkRenderWindow()
>>>> renWindow.SetSize(512, 512)
>>>> renWindow.AddRenderer( renderer )
>>>>
>>>> # render window interactor
>>>> renWinInteractor = vtkRenderWindowInteractor()
>>>> renWinInteractor.SetRenderWindow( renWindow )
>>>> # add the actors to the renderer
>>>> renderer.AddActor( gridActor )
>>>> renderer.AddActor( scaleBarActor )
>>>>
>>>> #show axes
>>>> axesActor = vtkAxesActor()
>>>> widget = vtkOrientationMarkerWidget()
>>>> widget.SetOrientationMarker( axesActor )
>>>> widget.SetInteractor( renWinInteractor )
>>>> widget.SetViewport( 0.0, 0.0, 0.4, 0.4 )
>>>> widget.SetEnabled( 1 )
>>>> widget.InteractiveOff()
>>>>
>>>> # render
>>>> renderer.ResetCamera();
>>>> renWindow.Render()
>>>> # initialize and start the interactor
>>>> renWinInteractor.Initialize()
>>>> renWinInteractor.Start()
>>>> ==================================================
>>>>
>>>>
>>>>  Thanks and Regards,
>>>>
>>>>  Manjunath K E
>>>>  Help Ever Hurt Never
>>>>
>>>>
>>>> On Tue, Aug 4, 2015 at 12:31 AM, Dan Lipsa <dan.lipsa at kitware.com>
>>>> wrote:
>>>>
>>>>> Manjunath,
>>>>> Can you share the script you are trying to run? This seems like a
>>>>> problem with the script rather than an installation issue.
>>>>>
>>>>> On Mon, Aug 3, 2015 at 2:16 PM Manjunath K E <ke.manjunath at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Shawn,
>>>>>>
>>>>>> I followed your instructions, now the vtk importing problem is
>>>>>> solved.
>>>>>> But, following error is obtained
>>>>>>
>>>>>> ERROR: In
>>>>>> /home/kitware/Desktop/vtkbuild/build/vtk/src/vtk/Rendering/OpenGL/vtkOpenGLTexture.cxx,
>>>>>> line 200
>>>>>> vtkOpenGLTexture (0x2f2ac90): No scalar values found for texture
>>>>>> input!
>>>>>>
>>>>>> The error is seen for every frame
>>>>>>
>>>>>>  Thanks and Regards,
>>>>>>
>>>>>>  Manjunath K E
>>>>>>  Help Ever Hurt Never
>>>>>>
>>>>>>
>>>>>> On Mon, Aug 3, 2015 at 11:36 PM, Shawn Waldon <
>>>>>> shawn.waldon at kitware.com> wrote:
>>>>>>
>>>>>>> Hi Manjunath,
>>>>>>>
>>>>>>> Please keep discussions on the list so that others can benefit later.
>>>>>>>
>>>>>>> I haven't used an install tree on Linux for a while but according to
>>>>>>> my notes you should need the following assuming it is installed to
>>>>>>> /usr/local:
>>>>>>>
>>>>>>> export
>>>>>>> LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib/python2.7/site-packages/vtk:$LD_LIBRARY_PATH
>>>>>>>
>>>>>>> export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
>>>>>>>
>>>>>>> HTH,
>>>>>>> Shawn
>>>>>>>
>>>>>>> On Mon, Aug 3, 2015 at 1:59 PM, Manjunath K E <
>>>>>>> ke.manjunath at gmail.com> wrote:
>>>>>>>
>>>>>>>> Hi Shawn
>>>>>>>>
>>>>>>>> Thanks for the reply.
>>>>>>>> My python script is set up to use the system's python not vtkpython.
>>>>>>>>
>>>>>>>> I have set export
>>>>>>>> PYTHONPATH="/usr/local/lib/python2.7/site-packages/vtk/:$PYTHONPATH".
>>>>>>>> export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
>>>>>>>>
>>>>>>>> I have installed vtk-6.2 to /usr/local.
>>>>>>>>
>>>>>>>> Is the should i change the values of PYTHONPATH and LD_LIBRARY_PATH
>>>>>>>> to something else.
>>>>>>>>
>>>>>>>>  Thanks and Regards,
>>>>>>>>
>>>>>>>>  Manjunath K E
>>>>>>>>  Help Ever Hurt Never
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Aug 3, 2015 at 11:17 PM, Shawn Waldon <
>>>>>>>> shawn.waldon at kitware.com> wrote:
>>>>>>>>
>>>>>>>>> Hi Manjunath,
>>>>>>>>>
>>>>>>>>> Is your python script set up to use vtkpython as the interpreter?
>>>>>>>>> Or is it using the system's python?  If you are trying to import vtk from
>>>>>>>>> system python you have to set your LD_LIBRARY_PATH and PYTHONPATH
>>>>>>>>> environment variables.  If you want to change the script to use vtkpython
>>>>>>>>> then change the first like to #!/path/to/vtkpython
>>>>>>>>>
>>>>>>>>> HTH,
>>>>>>>>> Shawn
>>>>>>>>>
>>>>>>>>> On Mon, Aug 3, 2015 at 1:43 PM, Manjunath K E <
>>>>>>>>> ke.manjunath at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Hi all
>>>>>>>>>>
>>>>>>>>>> I have installed VTK 6.2 along with vtk 6.2 python  interface on
>>>>>>>>>> ubuntu 14.04 manually.
>>>>>>>>>>
>>>>>>>>>> When I run vtkpython in interpreter mode, the import of vtk is
>>>>>>>>>> successful.
>>>>>>>>>> It doesn't have any problem  and the same is shown below.
>>>>>>>>>>
>>>>>>>>>> ===========================================================
>>>>>>>>>> manju at iiitb-gvcl-Z800:~/manju/academics/iiitb/project/codes/incois__laptp/src_vtk6$
>>>>>>>>>> vtkpython
>>>>>>>>>> vtk version 6.2.0
>>>>>>>>>> Python 2.7.2 (default, Feb 12 2015, 18:30:44)
>>>>>>>>>> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>>>>>>>>>> Type "help", "copyright", "credits" or "license" for more
>>>>>>>>>> information.
>>>>>>>>>> >>> from vtk import *
>>>>>>>>>> >>> print vtk
>>>>>>>>>> <module 'vtk' from
>>>>>>>>>> '/usr/local/lib/python2.7/site-packages/vtk/__init__.pyc'>
>>>>>>>>>> >>>
>>>>>>>>>> ===========================================================
>>>>>>>>>>
>>>>>>>>>> But, If i run a python script then an error is obtained for this
>>>>>>>>>> line "from vtk import *". The error is as shown below.
>>>>>>>>>> ===========================================================
>>>>>>>>>> manju at iiitb-gvcl-Z800:~/manju/academics/iiitb/project/codes/incois__laptp/src_vtk6$
>>>>>>>>>> ./demo1.py
>>>>>>>>>> Traceback (most recent call last):
>>>>>>>>>>   File "./demo1.py", line 6, in <module>
>>>>>>>>>>     from vtk import *
>>>>>>>>>> ImportError: No module named vtk
>>>>>>>>>> ===========================================================
>>>>>>>>>>
>>>>>>>>>> Please help me in solving this issue. I appreciate your time and
>>>>>>>>>> help.
>>>>>>>>>>
>>>>>>>>>>  Thanks and Regards,
>>>>>>>>>>
>>>>>>>>>>  Manjunath K E
>>>>>>>>>>  Help Ever Hurt Never
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> 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
>>>>>>>>>>
>>>>>>>>>> Search the list archives at:
>>>>>>>>>> http://markmail.org/search/?q=vtkusers
>>>>>>>>>>
>>>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>>>>
>>>>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>>>>
>>>>>
>>>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150810/7c9b273c/attachment.html>


More information about the vtkusers mailing list