[vtkusers] from vtk import * ImportError: (Python VTK 6.2 on ubuntu 14.04)
Dan Lipsa
dan.lipsa at kitware.com
Tue Aug 4 12:45:48 EDT 2015
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/20150804/15c6e7a5/attachment.html>
More information about the vtkusers
mailing list