问题描述
我的系统是 Ubuntu 16.04,我的 Python 版本是 3.5.我已经使用 Python 包装器将 vtk 7.1.0
安装到 /home/why/software/vtk/7.1.0/
中.此外,我将以下行添加到 .bashrc
My system is Ubuntu 16.04 and my Python version is 3.5. I have installed vtk 7.1.0
into /home/why/software/vtk/7.1.0/
with Python wrapper. Furthermore, I add the following line into .bashrc
export PYTHONPATH=$PYTHONPATH:/home/why/software/vtk/7.1.0/lib/python3.5/site-packages
而且我可以在ipython3中导入vtk
并正常使用
And I can import vtk
in ipython3 and use it normally.
但是当我通过
sudo -H pip3 install mayavi
我收到以下错误:
Running setup.py bdist_wheel for mayavi ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-1_ze16zr/mayavi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmp55qp27ekpip-wheel- --python-tag cp35:
running bdist_wheel
running build
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-1_ze16zr/mayavi/setup.py", line 499, in <module>
**config
File "/usr/lib/python3/dist-packages/numpy/distutils/core.py", line 169, in setup
return old_setup(**new_attr)
File "/usr/lib/python3.5/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.5/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3/dist-packages/wheel/bdist_wheel.py", line 179, in run
self.run_command('build')
File "/usr/lib/python3.5/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.5/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/tmp/pip-build-1_ze16zr/mayavi/setup.py", line 311, in run
build_tvtk_classes_zip()
File "/tmp/pip-build-1_ze16zr/mayavi/setup.py", line 297, in build_tvtk_classes_zip
gen_tvtk_classes_zip()
File "tvtk/setup.py", line 50, in gen_tvtk_classes_zip
from tvtk.code_gen import TVTKGenerator
File "/tmp/pip-build-1_ze16zr/mayavi/tvtk/code_gen.py", line 10, in <module>
import vtk
ImportError: No module named 'vtk'
如何解决这个问题?非常感谢您的帮助.
How to fix this problem? Thanks very much for your help.
根据 Mike Müller 的建议,我现在可以安装 mayavi
.但我运行了一个简单的测试,如下所示:
By Mike Müller suggestion, I can install mayavi
now. But I run a simple test like following:
In [1]: import numpy as np
In [2]: from mayavi import mlab
In [3]: x, y, z, value = np.random.random((4, 40))
In [4]: mlab.points3d(x, y, z, value)
Out[4]: <mayavi.modules.glyph.Glyph at 0x7f3190ffca98>
我只看到一个灰色的死窗,里面没有任何人物.那么如何解决这个问题?
and I just get a gray dead window without any figure in it. So how to fixed this problem?
推荐答案
第 1 部分 - 安装
如果您想/需要以 root 身份安装,请先更改为 root,然后导出 PYTHONPATH
:
sudo -s
export PYTHONPATH=$PYTHONPATH:/home/why/software/vtk/7.1.0/lib/python3.5/site-packages
pip3 install mayavi
Root 不承认您作为其他用户设置的环境变量.
Root does not acknowledge the environmental variables you set as a another user.
您需要调用 mlab.show()
来显示您的可视化:
You need to call mlab.show()
to show your visualization:
import numpy as np
from mayavi import mlab
x, y, z, value = np.random.random((4, 40))
mlab.points3d(x, y, z, value)
mlab.show()
这篇关于`如何通过`pip3`和`vtk`安装和运行`mayavi`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!