使用pip安裝Mayavi - 沒有名為vtk的模塊

[英]installing Mayavi with pip - no module named vtk


I want to use Mayavi.

我想用Mayavi。

Situation

  • I use a MacBook Air, with OSX 10.7.3.
  • 我使用MacBook Air,OSX 10.7.3。

  • I use Python 2.7.2
  • 我使用Python 2.7.2

  • I have virtualenv installed. But I have not used it for this installation.
  • 我安裝了virtualenv。但我還沒有用它來安裝。

I've manually installed all it's dependencies, including VTK.

我手動安裝了它的所有依賴項,包括VTK。

For VTK, I followed its installation guide and installed the python wrapper.

對於VTK,我按照其安裝指南安裝了python包裝器。

Now if I open a new terminal window and open python, I can import vtk without any error.

現在,如果我打開一個新的終端窗口並打開python,我可以導入vtk而不會出現任何錯誤。

Problem

I try to install Mayavi with the following command:

我嘗試使用以下命令安裝Mayavi:

pip install mayavi

But the following error occurs:

但發生以下錯誤:

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'

I think the problem is with vtk.

我認為問題在於vtk。

Can anyone help me?

誰能幫我?

Other Details

Running sudo pip install mayavi does not solve the problem.

運行sudo pip install mayavi無法解決問題。

I thought this might help

我認為這可能會有所幫助

› 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'>
>>> 

My PYTHONPATH is empty.

我的PYTHONPATH是空的。

6 个解决方案

#1


10  

Your pip is probably using a different python, kind of you have vtk installed using /usr/local/bin/python, while your pip binary uses /usr/bin/python.

你的pip可能正在使用不同的python,你使用/ usr / local / bin / python安裝vtk,而你的pip二進制文件使用/ usr / bin / python。

Check it:

$ head -n1 $(which pip)

In order to get it solved, you can choose to use a virtualenv, or install pip using /usr/local/bin/python:

為了解決它,您可以選擇使用virtualenv,或使用/ usr / local / bin / python安裝pip:

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

For more installation instructions, see http://www.pip-installer.org/en/latest/installing.html

有關更多安裝說明,請訪問http://www.pip-installer.org/en/latest/installing.html

#2


16  

I'm on Debian but this should work for you as well

我在Debian上,但這對你也有用

I was stuck with installing vtk into a virtualenv, after hours of search with no results I did the following and it worked.

我堅持將vtk安裝到virtualenv中,經過數小時的搜索后沒有任何結果我做了以下工作。

  1. install python-vtk from repositories systemwide

    從系統范圍內的存儲庫安裝python-vtk

  2. copy vtk folder from /usr/lib/pymodules/python2.7 to /PATH/TO/YOUR/VIRTUALENV/lib/python2.7/site-packages

    將/usr/lib/pymodules/python2.7中的vtk文件夾復制到/PATH/TO/YOUR/VIRTUALENV/lib/python2.7/site-packages

In your case the system-wide python packages folder would probably be different but you can easily find it by firing up system python and entering the following:

在您的情況下,系統范圍的python包文件夾可能會有所不同,但您可以通過啟動系統python並輸入以下內容輕松找到它:

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

After this trick mayavi was succesfully installed into my virtualenv using pip install mayavi and pip install envisage.

在這個技巧之后,使用pip install mayavi和pip install envisage成功地將mayavi安裝到我的virtualenv中。

Edit: instead of copying it might better to just symlink the folder in step 2

編輯:而不是復制它可能更好地只是在步驟2中符號鏈接該文件夾

#3


8  

I had the same problem and the first answer didn't help me because pip was in the right directory, but it turned out I didn't have vtk installed - running sudo apt-get install python-vtk fixed the issue and I was able to successfully run pip install mayavi after that.

我有同樣的問題,第一個答案沒有幫助我,因為pip在正確的目錄中,但事實證明我沒有安裝vtk - 運行sudo apt-get install python-vtk修復了問題,我能夠之后成功運行pip install mayavi。

#4


3  

I had the same problem when installing mayavi with python installed in pyenv, and I solved this problem by copy directory to /home/myname/.pyenv/versions/2.7.12/lib/python2.7/site-packages, below is my method:

我在pyenv中安裝了python安裝mayavi時出現了同樣的問題,我通過復制目錄解決了這個問題到/home/myname/.pyenv/versions/2.7.12/lib/python2.7/site-packages,下面是我的方法:

  1. install vtk and python-vtk

    安裝vtk和python-vtk

    sudo apt-get install vtk6
    sudo apt-get install python-vtk
    
  2. try python -c "import vtk", if failed again, go to step 3

    嘗試python -c“import vtk”,如果再次失敗,請轉到步驟3

  3. the import error may caused by the loss of vtk package folder in your current python, so we should find the vtk folder and copy to your current python(most possible the python in pyenv shims directory)'s directory .

    導入錯誤可能是由於當前python中vtk包文件夾丟失引起的,所以我們應該找到vtk文件夾並復制到你當前的python(最有可能是pyenv shims目錄下的python)的目錄。

    the path of the vtk folder in my ubuntu is

    我的ubuntu中的vtk文件夾的路徑是

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

    just copy the vtk folder to your current python's /site-packages, e.g.

    只需將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. try python -c "import vtk" again.

    再次嘗試python -c“import vtk”。

  5. if no import error, just do

    如果沒有導入錯誤,就行了

    pip install mayavi
    

#5


0  

I insisted in sudo install for several times, finally got solved, don't know how to explain.

我堅持在sudo上安裝好幾次,終於搞定了,不知道怎么解釋。

sudo python2 -m pip install mayavi

sudo python3 -m pip install mayavi

#6


-1  

I installed vtk using Homebrew:

我用Homebrew安裝了vtk:

$ brew install vtk

hope this helps.

希望這可以幫助。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/08/29/72ffa1f89aae26d8ac3e35d36d050ec0.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com