Below is my script code:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
import json
import math
import time
import base64
from paraview.simple import *
nowtime = lambda: int(round(time.time() * 1000))
rawFileUrl = sys.argv[1]
imgSize = json.loads(sys.argv[2])
# index = json.loads(sys.argv[3])
##### snapshot the 3D picture
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'Image Reader'
rawReader = ImageReader(FileNames=[rawFileUrl])
# rawReader = ImageReader(FilePrefix=rawFileUrl)
# Properties modified on a15704801455411_wholeCore_210x210x365_0p4947x0p4947x0p625mm_8bitraw
rawReader.ReadAsImageStack = 1
rawReader.DataScalarType = 'unsigned char'
rawReader.DataExtent = [0, imgSize['width']-1, 0, imgSize['height']-1, 0, imgSize['pages']-1]
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# renderView1.ViewSize = [1216, 808]
# show data in view
rawReaderDisplay = Show(rawReader, renderView1)
# trace defaults for the display properties.
rawReaderDisplay.Representation = 'Outline'
rawReaderDisplay.ColorArrayName = ['POINTS', '']
rawReaderDisplay.OSPRayScaleArray = 'ImageFile'
rawReaderDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
rawReaderDisplay.SelectOrientationVectors = 'ImageFile'
rawReaderDisplay.ScaleFactor = imgSize['pages']/10
rawReaderDisplay.SelectScaleArray = 'ImageFile'
rawReaderDisplay.GlyphType = 'Arrow'
rawReaderDisplay.GlyphTableIndexArray = 'ImageFile'
rawReaderDisplay.DataAxesGrid = 'GridAxesRepresentation'
rawReaderDisplay.PolarAxes = 'PolarAxesRepresentation'
rawReaderDisplay.ScalarOpacityUnitDistance = 1.8646893247972678
# rawReaderDisplay.IsosurfaceValues = [127.5]
rawReaderDisplay.Slice = imgSize['pages']//2
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
rawReaderDisplay.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 255.0, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
rawReaderDisplay.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 255.0, 1.0, 0.5, 0.0]
# reset view to fit data
renderView1.ResetCamera()
# # get the material library
# materialLibrary1 = GetMaterialLibrary()
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(rawReaderDisplay, ('POINTS', 'ImageFile'))
# rescale color and/or opacity maps used to include current data range
rawReaderDisplay.RescaleTransferFunctionToDataRange(True, True)
# change representation type
rawReaderDisplay.SetRepresentationType('Volume')
# get color transfer function/color map for 'ImageFile'
imageFileLUT = GetColorTransferFunction('ImageFile')
imageFileLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 127.5, 0.865003, 0.865003, 0.865003, 255.0, 0.705882, 0.0156863, 0.14902]
imageFileLUT.ScalarRangeInitialized = 1.0
# get opacity transfer function/opacity map for 'ImageFile'
imageFilePWF = GetOpacityTransferFunction('ImageFile')
imageFilePWF.Points = [0.0, 0.0, 0.5, 0.0, 139.78915405273438, 0.5073529481887817, 0.5, 0.0, 255.0, 1.0, 0.5, 0.0]
imageFilePWF.ScalarRangeInitialized = 1
# Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
imageFileLUT.ApplyPreset('Grayscale', True)
# show color bar/color legend
# rawReaderDisplay.SetScalarBarVisibility(renderView1, True)
# current camera placement for renderView1
renderView1.CameraPosition = [-553.2213163882634, 1225.361636475504, 1340.9145427277479]
renderView1.CameraFocalPoint = [imgSize['width']/2, imgSize['height']/2, imgSize['pages']/2]
renderView1.CameraViewUp = [0.2719455703783571, 0.8080929324180035, -0.5225240849259124]
renderView1.CameraParallelScale = (imgSize['width'] + imgSize['height'])/2.2
# reset view to fit data
renderView1.ResetCamera()
# save screenshot
threeDSnapUrl = str(nowtime()) + '_3d.png'
SaveScreenshot('/tmp/'+ threeDSnapUrl, renderView1, ImageResolution=[800, 800])
This script works if I use pvpython to run it. While if I run it using the conda included python, it will give the error shown in my original post.
As you mentioned, it may be related to conda when they packed the vtk or paraview(I guess)