使用PyCharm安装mayavi

       我是在docker容器里安装,里面的环境是python3,因此mayavi依赖的PyQT需要安装PyQT5,现在PyCharm的python package tool window里左上方的搜索栏里输入PyQt5然后点击右上方的Install安装包PyQt5,然后在搜索栏输入vtk 选择安装最新的9.2.2版,然后在搜索栏里输入mayavi,也选择latest版本进行安装,结果试了几次都失败,选择了mayavi低一点的几个版本试了也不行,每次都是类似下面segment fault的错误:

Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting mayavi
  Using cached https://mirrors.aliyun.com/pypi/packages/8a/54/90dd60c62e685ee56bdfaa6a7af62b0c762568a962e3137fc954b4f845bc/mayavi-4.8.0.tar.gz (19.8 MB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: apptools in /usr/local/lib/python3.6/site-packages (from mayavi) (5.2.0)
Requirement already satisfied: envisage in /usr/local/lib/python3.6/site-packages (from mayavi) (6.1.0)
Requirement already satisfied: numpy in /root/.local/lib/python3.6/site-packages (from mayavi) (1.19.5)
Requirement already satisfied: pyface>=6.1.1 in /usr/local/lib/python3.6/site-packages (from mayavi) (7.4.2)
Requirement already satisfied: pygments in /usr/local/lib/python3.6/site-packages (from mayavi) (2.12.0)
Requirement already satisfied: traits>=6.0.0 in /usr/local/lib64/python3.6/site-packages (from mayavi) (6.4.1)
Requirement already satisfied: traitsui>=7.0.0 in /usr/local/lib/python3.6/site-packages (from mayavi) (7.4.1)
Requirement already satisfied: vtk in /usr/local/lib64/python3.6/site-packages (from mayavi) (9.2.2)
Requirement already satisfied: importlib-resources>=1.1.0 in /usr/local/lib/python3.6/site-packages (from pyface>=6.1.1->mayavi) (5.4.0)
Requirement already satisfied: importlib-metadata>=3.6.0 in /usr/local/lib/python3.6/site-packages (from pyface>=6.1.1->mayavi) (4.8.3)
Requirement already satisfied: configobj in /usr/local/lib/python3.6/site-packages (from apptools->mayavi) (5.0.6)
Requirement already satisfied: setuptools in /usr/local/lib/python3.6/site-packages (from envisage->mayavi) (59.5.0)
Requirement already satisfied: wslink>=1.0.4 in /usr/local/lib/python3.6/site-packages (from vtk->mayavi) (1.8.2)
Requirement already satisfied: matplotlib>=2.0.0 in /usr/local/lib64/python3.6/site-packages (from vtk->mayavi) (3.3.4)
Requirement already satisfied: typing-extensions>=3.6.4 in /root/.local/lib/python3.6/site-packages (from importlib-metadata>=3.6.0->pyface>=6.1.1->mayavi) (4.1.1)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.6/site-packages (from importlib-metadata>=3.6.0->pyface>=6.1.1->mayavi) (3.6.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib64/python3.6/site-packages (from matplotlib>=2.0.0->vtk->mayavi) (1.2.0)
Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.6/site-packages (from matplotlib>=2.0.0->vtk->mayavi) (2.8.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/site-packages (from matplotlib>=2.0.0->vtk->mayavi) (0.11.0)
Requirement already satisfied: pillow>=6.2.0 in /root/.local/lib/python3.6/site-packages (from matplotlib>=2.0.0->vtk->mayavi) (8.4.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.6/site-packages (from matplotlib>=2.0.0->vtk->mayavi) (3.0.9)
Requirement already satisfied: aiohttp<4 in /usr/local/lib64/python3.6/site-packages (from wslink>=1.0.4->vtk->mayavi) (3.8.1)
Requirement already satisfied: six in /usr/local/lib/python3.6/site-packages (from configobj->apptools->mayavi) (1.16.0)
Requirement already satisfied: idna-ssl>=1.0 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (1.1.0)
Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib64/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (1.2.0)
Requirement already satisfied: asynctest==0.13.0 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (0.13.0)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (4.0.2)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (21.4.0)
Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (1.2.0)
Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib64/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (5.2.0)
Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /usr/local/lib/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (2.0.12)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib64/python3.6/site-packages (from aiohttp<4->wslink>=1.0.4->vtk->mayavi) (1.7.2)
Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.6/site-packages (from idna-ssl>=1.0->aiohttp<4->wslink>=1.0.4->vtk->mayavi) (2.8)
Building wheels for collected packages: mayavi
  Building wheel for mayavi (setup.py): started
  Building wheel for mayavi (setup.py): finished with status 'error'
  Running setup.py clean for mayavi
Failed to build mayavi
Installing collected packages: mayavi
    Running setup.py install for mayavi: started
    Running setup.py install for mayavi: finished with status 'error'

  ERROR: Command errored out with exit status -11:
   command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-4s0oq87x
       cwd: /tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/
  Complete output (153 lines):
  running bdist_wheel
  running build
  ----------------------------------------------------------------------
  Deleting possibly old TVTK classes
  Building TVTK classes... vtkAnimationCue: Ignoring method: Get/SetDirection
  default: 1, range: None
  vtkContextDevice2D: Ignoring method: Get/SetViewportRect
  default: [225, 0, 37940736, 0], range: None
  vtkContextDevice2D: Ignoring method: Get/SetViewportSize
  default: [41, 0], range: None
  vtkEventDataForDevice: Ignoring method: Get/SetAction
  default: -1, range: None
  vtkEventDataForDevice: Ignoring method: Get/SetDevice
  default: -1, range: None
  vtkFXAAOptions: Ignoring method: Get/SetDebugOptionValue
  default: 0, range: None
  vtkIncrementalForceLayout: Ignoring method: Get/SetGravityPoint
  default: [200.0, 200.0], range: None
  vtkOpenGLBufferObject: Ignoring method: Get/SetType
  default: 0, range: None
  vtkOpenGLFXAAFilter: Ignoring method: Get/SetDebugOptionValue
  default: 0, range: None
  vtkRenderWidget: Ignoring method: Get/SetPosition
  default: [0, 0], range: None
  vtkRenderWidget: Ignoring method: Get/SetSize
  default: [300, 300], range: None
  vtkShader: Ignoring method: Get/SetType
  default: 3, range: None
  vtkVolumeTexture: Ignoring method: Get/SetPartitions
  default: [1, 1, 1], range: None
  vtkChartMatrix: Ignoring method: Get/SetFillStrategy
  default: 0, range: None
  vtkChartMatrix: Ignoring method: Get/SetGutter
  default: [15.0, 15.0], range: None
  vtkChartMatrix: Ignoring method: Get/SetRect
  default: [0, 0, 100, 100], range: None
  vtkChartMatrix: Ignoring method: Get/SetSize
  default: [0, 0], range: None
  vtkContextArea: Ignoring method: Get/SetDrawAreaBounds
  default: [0.0, 0.0, 300.0, 300.0], range: None
  vtkContextArea: Ignoring method: Get/SetDrawAreaResizeBehavior
  default: 0, range: None
  vtkContextArea: Ignoring method: Get/SetFixedMargins
  default: [0, 0, 0, 0], range: None
  vtkContextArea: Ignoring method: Get/SetFixedRect
  default: [0, 0, 300, 300], range: None
  vtkContextArea: Ignoring method: Get/SetGeometry
  default: [0, 0, 300, 300], range: None
  vtkImplicitProjectOnPlaneDistance: Ignoring method: Get/SetNorm
  default: 2, range: None
  vtkOpenGLVertexBufferObject: Ignoring method: Get/SetCoordShiftAndScaleMethod
  default: 0, range: None
  vtkSimple3DCirclesStrategy: Ignoring method: Get/SetMarkedValue
  default: (invalid), range: None
  vtkArrayNorm: Ignoring method: Get/SetWindow
  default: [0, 9223372036854775807), range: None
  vtkChart: Ignoring method: Get/SetSize
  default: [0.0, 0.0, 0.0, 0.0], range: None
  vtkChartXYZ: Ignoring method: Get/SetAxisColor
  default: [0, 0, 0, 255], range: None
  vtkEuclideanClusterExtraction: Radius not updatable (VTK 9.1 bug - value not properly initialized)
  Warning: We cannot determine the trait type of vtkHigherOrderHexahedron.Order
  Warning: We cannot determine the trait type of vtkHigherOrderQuadrilateral.Order
  Warning: We cannot determine the trait type of vtkHigherOrderWedge.Order
  vtkHyperTreeGridPreConfiguredSource: Ignoring method: Get/SetCustomArchitecture
  default: 0, range: None
  vtkHyperTreeGridPreConfiguredSource: Ignoring method: Get/SetHTGMode
  default: 0, range: None
  vtkLightingMapPass: Ignoring method: Get/SetRenderType
  default: 0, range: None
  vtkPlot: Ignoring method: Get/SetShiftScale
  default: [0.0, 0.0, 1.0, 1.0], range: None
  vtkScatterPlotMatrix: Ignoring method: Get/SetActivePlot
  default: [0, -2], range: None
  vtkScatterPlotMatrix: Ignoring method: Get/SetScatterPlotSelectedActiveColor
  default: [0, 204, 0, 102], range: None
  vtkScatterPlotMatrix: Ignoring method: Get/SetScatterPlotSelectedRowColumnColor
  default: [204, 0, 0, 102], range: None
  vtkScatterPlotMatrix: Ignoring method: Get/SetSize
  default: [0, 0], range: None
  vtkSparseArray_I10vtkVariantE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_I10vtkVariantE: Ignoring method: Get/SetNullValue
  default: (invalid), range: None
  vtkSparseArray_I12vtkStdStringE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IaE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IcE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IdE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IfE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IhE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IiE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IjE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IlE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_ImE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IsE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_ItE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IxE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkSparseArray_IyE: Ignoring method: Get/SetExtents
  default: , range: None
  vtkThresholdTable: Ignoring method: Get/SetMaxValue
  default: 2147483647, range: None
  vtkThresholdTable: Ignoring method: Get/SetMinValue
  default: 0, range: None
  vtkTransferAttributes: Ignoring method: Get/SetDefaultValue
  default: 1, range: None
  Bad to call vtkUniformHyperTreeGrid::GetXCoordinates
  Bad to call vtkUniformHyperTreeGrid::GetYCoordinates
  Bad to call vtkUniformHyperTreeGrid::GetZCoordinates
  vtkChartBox: Ignoring method: Get/SetSize
  default: [0.0, 0.0, 0.0, 0.0], range: None
  vtkColorLegend: Ignoring method: Get/SetPosition
  default: [0.0, 0.0, 0.0, 0.0], range: None
  Warning: We cannot determine the trait type of vtkImageMask.MaskedOutputValue
  vtkMolecule: Ignoring method: Get/SetLatticeOrigin
  default: [0.0, 0.0, 0.0], range: None
  vtkPOpenFOAMReader: Ignoring method: Get/SetCaseType
  default: 1, range: None
  Fatal Python error: Segmentation fault
  
  Current thread 0x00007f39ab5c0740 (most recent call first):
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/vtk_parser.py", line 705 in _find_get_set_methods
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/vtk_parser.py", line 488 in _organize_methods
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/vtk_parser.py", line 154 in parse
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/wrapper_gen.py", line 341 in _gen_methods
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/wrapper_gen.py", line 242 in generate_code
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/code_gen.py", line 235 in _write_wrapper_class
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/tvtk/code_gen.py", line 142 in generate_code
    File "tvtk/setup.py", line 98 in gen_tvtk_classes_zip
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py", line 254 in build_tvtk_classes_zip
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py", line 268 in run
    File "/usr/lib64/python3.6/distutils/dist.py", line 974 in run_command
    File "/usr/lib64/python3.6/distutils/cmd.py", line 313 in run_command
    File "/usr/local/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 299 in run
    File "/usr/lib64/python3.6/distutils/dist.py", line 974 in run_command
    File "/usr/lib64/python3.6/distutils/dist.py", line 955 in run_commands
    File "/usr/lib64/python3.6/distutils/core.py", line 148 in setup
    File "/usr/local/lib/python3.6/site-packages/setuptools/__init__.py", line 153 in setup
    File "/root/.local/lib/python3.6/site-packages/numpy/distutils/core.py", line 169 in setup
    File "/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py", line 464 in
    File "", line 1 in

    ----------------------------------------
ERROR: Command errored out with exit status -11: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9iiorris/mayavi_ce17df6e474c44e9bd05d7c328bb7e02/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-bnbwj46a/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6m/mayavi Check the logs for full command output.

看了一下网上别人在windows里安装时好像都是使用的比较低版本的vtk,于是我实验了一些低一点版本的vtk,再来组合低一点版本的mayavi,结果发现 vtk 8.1.2  +  mayavi 4.8.0是可以成功安装的,vtk 8.2 + mayavi 4.7.3也可以,反正多试一下找个自己觉得版本算高的就行了。

如果是安装在host上,应该可以用了,如果是安装在docker容器内,运行利用mayavi进行点云可视化之类的程序时很可能还是QT会报错,在~/.bashrc里增加export QT_DEBUG_PLUGINS=1并用source ~/.bashrc生效,再运行程序让QT报出详细错误:

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
Cannot load library /usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)
QLibraryPrivate::loadPlugin failed on "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so" : "Cannot load library /usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

类似这样的文件不存在的问题好说,安装就是,用ldd命令查看还缺哪些文件:

ldd /usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so

    libxcb-icccm.so.4 => not found
    libxcb-image.so.0 => not found
    *libxcb-util.so.1 => not found
    libxcb-keysyms.so.1 => not found
    libxcb-render-util.so.0 => not found
    libxkbcommon-x11.so.0 => not found

如果你直接安装指定具体版本号后缀了的文件yum install libxcb-icccm.so.4,会导致运行时又这样报错:

Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
Cannot load library /usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: wrong ELF class: ELFCLASS32)
QLibraryPrivate::loadPlugin failed on "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so" : "Cannot load library /usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: wrong ELF class: ELFCLASS32)"
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.

Aborted (core dumped)

这种wrong ELF class: ELFCLASS32错误表示安装的32位的文件,但是程序需要的是64位的文件,所以需要使用类似这样的命令来选择安装x86_64版的文件:

yum install libxcb-icccm* libxcb-image* libxcb-keysyms* libxcb-render-util* libxkbcommon-x11*

(注意,在不同的docker环境里缺的文件可能有不同,看具体报错情况)

把上面缺的6个文件都安装了后,再运行程序可能又会报这样的错误:

Got keys from plugin meta data ("webp")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/imageformats" ...
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqgif.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqicns.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqico.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqjpeg.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqsvg.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqtga.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqtiff.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqwbmp.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqwebp.so"
QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/accessiblebridge" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessiblebridge" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/accessible" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessible" ...
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast

ERROR: In /work/standalone-x64-build/VTK-source/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx, line 785
vtkXOpenGLRenderWindow (0x491d930): GLEW could not be initialized.
Segmentation fault (core dumped)

这种错误是当前的容器类没有mesa驱动,用下面的命令安装:

#Centos
yum install mesa*
yum install glut

#Ubuntu
sudo apt install mesa-common-dev freeglut3-dev libglfw3-dev libgles2-mesa-dev libglew-dev

再运行程序又报错:

Got keys from plugin meta data ("webp")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/imageformats" ...
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqgif.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqicns.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqico.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqjpeg.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqsvg.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqtga.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqtiff.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqwbmp.so"
loaded library "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/imageformats/libqwebp.so"
QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/accessiblebridge" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessiblebridge" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/local/lib64/python3.6/site-packages/PyQt5/Qt5/plugins/accessible" ...
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/accessible" ...
libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
ERROR: In /work/standalone-x64-build/VTK-source/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx, line 785
vtkXOpenGLRenderWindow (0x6002f30): GLEW could not be initialized.

Segmentation fault (core dumped)
这是因为当前的容器内没有opengl驱动,一种办法是创建容器是把Host上的cuda和opengl驱动所在目录映射进入容器对应的路径,参见[docker][mayavi] libGL error: No matching fbConfigs or visuals found · Issue #1 · SoonminHwang/dockers · GitHub

另一种是到Docker Hub上选取合适版本的cudgl镜像后直接拉取cudagl镜像来创建容器,例如:

sudo docker pull nvidia/cudagl:11.4.2-devel-ubuntu18.04

我选择后者,后者比较简单,第一种方法比较麻烦。

拉取nvida/cudagl docker image后创建容器:

sudo nvidia-docker run -itd --privileged --pid host --network host --ipc host --name "lddata-nvidia-cudagl-11.4.2-devel" \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw -v /var/run/dbus:/var/run/dbus --device=/dev/dri:/dev/dri -e DISPLAY=$DISPLAY -e QT_X11_NO_MITSHM=1 \
-v /home/fychen/workspace:/workspace nvidia/cudagl:11.4.2-devel-ubuntu18.04 /bin/bash

然后安装python3和pip以及这个镜像里缺少的支持包libsm6,并设置aliyun为pip服务器镜像:

apt-get update
apt-get install python3 python3-pip libsm6
pip3 install --upgrade pip

pip3 config set global.index-url http://mirrors.aliyun.com/pypi/simple/
pip3 config set install.trusted-host mirrors.aliyun.com

再安装mayavi及其所需相关支持包:

pip install numpy==1.19.5 vtk==8.1.2 mayavi==4.8.0 PyQt5 torch==1.9.1

到此,环境安装就完成了!运行调研mayavi将点云可视化的程序即可看到点云图了:

python3 points_visual.py

使用PyCharm安装mayavi_第1张图片

 

你可能感兴趣的:(Python,python,QT,GL,opengl,mayavi)