35

我想使用 Mayavi。

情况

  • 我使用带有 OSX 10.7.3 的 MacBook Air。
  • 我使用 Python 2.7.2
  • 我已经virtualenv安装了。但是我没有将它用于此安装。

我已经手动安装了它的所有依赖项,包括VTK.

对于VTK,我按照它的安装指南安装了 python 包装器。

现在,如果我打开一个新的终端窗口并打开 python,我可以毫无错误地导入vtk

问题

我尝试使用以下命令安装 Mayavi:

pip install mayavi

但是会出现以下错误:

Downloading/unpacking mayavi
  Running setup.py egg_info for package mayavi
    build_src
    building extension "tvtk.array_ext" sources
    building data_files sources
    build_src: building npy-pkg config files

    no previously-included directories found matching 'artwork'
    no previously-included directories found matching 'docs/pdf'
Requirement already satisfied (use --upgrade to upgrade): apptools in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): traits in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): traitsui in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): configobj in /Library/Python/2.7/site-packages (from apptools->mayavi)
Requirement already satisfied (use --upgrade to upgrade): pyface in /Library/Python/2.7/site-packages (from traitsui->mayavi)
Installing collected packages: mayavi
  Running setup.py install for mayavi
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/Yasser/build/mayavi/setup.py", line 498, in <module>
        **config
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/core.py", line 186, in setup
        return old_setup(**new_attr)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
        dist.run_commands()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 57, in run
        r = self.setuptools_run()
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 31, in setuptools_run
        return old_install_mod._install.run(self)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 573, in run
        self.run_command('build')
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/Users/Yasser/build/mayavi/setup.py", line 303, in run
        build_tvtk_classes_zip()
      File "/Users/Yasser/build/mayavi/setup.py", line 290, in build_tvtk_classes_zip
        gen_tvtk_classes_zip()
      File "tvtk/setup.py", line 46, in gen_tvtk_classes_zip
        from code_gen import TVTKGenerator
      File "tvtk/code_gen.py", line 10, in <module>
        import vtk
    ImportError: No module named vtk
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/Users/Yasser/build/mayavi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/53/_trhc_0x0fb6kvx6bw_wrk500000gn/T/pip-Z4hpsW-record/install-record.txt:
    running install

running build

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "/Users/Yasser/build/mayavi/setup.py", line 498, in <module>

    **config

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/core.py", line 186, in setup

    return old_setup(**new_attr)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup

    dist.run_commands()

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 57, in run

    r = self.setuptools_run()

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 31, in setuptools_run

    return old_install_mod._install.run(self)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 573, in run

    self.run_command('build')

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command

    self.distribution.run_command(command)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Users/Yasser/build/mayavi/setup.py", line 303, in run

    build_tvtk_classes_zip()

  File "/Users/Yasser/build/mayavi/setup.py", line 290, in build_tvtk_classes_zip

    gen_tvtk_classes_zip()

  File "tvtk/setup.py", line 46, in gen_tvtk_classes_zip

    from code_gen import TVTKGenerator

  File "tvtk/code_gen.py", line 10, in <module>

    import vtk

ImportError: No module named vtk

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/Users/Yasser/build/mayavi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/53/_trhc_0x0fb6kvx6bw_wrk500000gn/T/pip-Z4hpsW-record/install-record.txt failed with error code 1 in /Users/Yasser/build/mayavi
Storing complete log in /Users/Yasser/Library/Logs/pip.log
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 8, in <module>
    load_entry_point('pip==1.1', 'console_scripts', 'pip')()
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/__init__.py", line 116, in main
    return command.main(args[1:], options)
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 141, in main
    log_fp = open_logfile(log_fn, 'w')
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 168, in open_logfile
    log_fp = open(filename, mode)
IOError: [Errno 13] Permission denied: '/Users/Yasser/Library/Logs/pip.log'

我认为问题出在vtk.

谁能帮我?

其他详情

跑步sudo pip install mayavi并不能解决问题。

我认为这可能会有所帮助

› which python
/usr/local/bin/python

› python
Python 2.7.2 (default, Feb 17 2012, 13:57:55) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
>>> vtk
<module 'vtk' from '/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/VTK-5.10.0-py2.7.egg/vtk/__init__.pyc'>
>>> 

PYTHONPATH的是空的。

4

6 回答 6

17

我在 Debian 上,但这也应该对你有用

我一直坚持将 vtk 安装到 virtualenv 中,经过数小时的搜索但没有任何结果,我做了以下操作并且它起作用了。

  1. 从系统范围的存储库安装 python-vtk

  2. 将 vtk 文件夹从 /usr/lib/pymodules/python2.7 复制到 /PATH/TO/YOUR/VIRTUALENV/lib/python2.7/site-packages

在您的情况下,系统范围的 python 包文件夹可能会有所不同,但您可以通过启动系统 python 并输入以下内容轻松找到它:

import vtk,sys
print(sys.modules['vtk'])

在这个技巧之后,使用 pip install mayavi 和 pip install 将 Mayavi 成功安装到我的 virtualenv 中。

编辑:而不是复制它可能会更好地在步骤 2 中对文件夹进行符号链接

于 2014-06-30T19:34:05.857 回答
12

pip可能正在使用不同python的类型,您已经vtk安装 using /usr/local/bin/python,而您的pip二进制文件使用/usr/bin/python.

核实:

$ head -n1 $(which pip)

为了解决它,您可以选择使用 avirtualenvpip使用安装/usr/local/bin/python

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | /usr/local/bin/python

有关更多安装说明,请参阅http://www.pip-installer.org/en/latest/installing.html

于 2012-08-30T23:09:38.847 回答
10

我遇到了同样的问题,第一个答案对我没有帮助,因为 pip 在正确的目录中,但事实证明我没有安装 vtk - 运行 sudo apt-get install python-vtk 解决了这个问题,我能够之后成功运行 pip install mayavi。

于 2014-05-18T00:08:17.560 回答
4

我在pyenv中安装python安装mayavi时遇到了同样的问题,我通过将目录复制到解决了这个问题/home/myname/.pyenv/versions/2.7.12/lib/python2.7/site-packages,下面是我的方法:

  1. 安装vtkpython-vtk

    sudo apt-get install vtk6
    sudo apt-get install python-vtk
    
  2. 尝试python -c "import vtk",如果再次失败,请转到步骤 3

  3. 导入错误可能是由于您当前的python中的vtk包文件夹丢失,所以我们应该找到vtk文件夹并复制到您当前的python(很可能是pyenv shims目录中的python)的目录。

    我的ubuntu中vtk文件夹的路径是

    /usr/lib/python2.7/dist-packages/vtk
    

    只需将vtk文件夹复制到您当前的 python 中/site-packages,例如

    cp -r /usr/lib/python2.7/dist-packages/vtk /home/myname/pyenv/versions/2.7.12/lib/python2.7/site-packages
    
  4. 再试python -c "import vtk"一次。

  5. 如果没有导入错误,就做

    pip install mayavi
    
于 2016-09-19T14:13:25.897 回答
1

坚持sudo安装了好几次,终于解决了,不知道怎么解释。

sudo python2 -m pip install mayavi

sudo python3 -m pip install mayavi

更新

我无法通过pip笔记本电脑安装。然后我安装最新mayavi

git clone https://github.com/enthought/mayavi.git
cd mayavi
pip install -r requirements.txt
pip install PyQt5  # replace this with any supported toolkit
python setup.py install  # or develop

安装后。测试

mayavi2

然后报告说找不到module PyQt5.Qtsvg,所以

sudo apt install python3-pyqt5.qtsvg

现在它起作用了。

于 2018-06-25T20:59:34.840 回答
-1

我使用 Homebrew 安装了 vtk:

$ brew install vtk

希望这可以帮助。

于 2015-10-27T19:03:29.527 回答