簡體   English   中英

python ImportError:無法導入名稱'multiarray'

[英]python ImportError: cannot import name 'multiarray'

我已經搜索了google的所有可用鏈接以解決此問題,但對我來說仍然沒有解決...

嘗試在python3中導入graph_tool時出現以下錯誤。 我同時安裝了python 2.7和3.6和anaconda。 我使用pipcondabrew安裝軟件包。 我有MacOS Sierra 10.12.3。

$ python3
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul  2 2016, 17:52:12) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from graph_tool.all import *
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/numpy/core/__init__.py", line 16, in <module>
    from . import multiarray
ImportError: cannot import name 'multiarray'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/graph_tool/__init__.py", line 104, in <module>
    import numpy
  File "/usr/local/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python3.6/site-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: cannot import name 'multiarray'


我的目錄/路徑上的一些信息:

>>> import sys
>>> print(('\n').join(sys.path))

/usr/local/lib/python3.6/site-packages
/Users/mymacbook/anaconda/lib/python35.zip
/Users/mymacbook/anaconda/lib/python3.5
/Users/mymacbook/anaconda/lib/python3.5/plat-darwin
/Users/mymacbook/anaconda/lib/python3.5/lib-dynload
/Users/mymacbook/.local/lib/python3.5/site-packages
/Users/mymacbook/anaconda/lib/python3.5/site-packages
/Users/mymacbook/anaconda/lib/python3.5/site-packages/Sphinx-1.4.6-py3.5.egg
/Users/mymacbook/anaconda/lib/python3.5/site-packages/aeosa
/Users/mymacbook/anaconda/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg
/usr/local/lib/python2.7/site-packages
/usr/local/Cellar/matplotlib/2.0.2/libexec/lib/python2.7/site-packages
/usr/local/Cellar/numpy/1.13.3/libexec/nose/lib/python2.7/site-packages

$ echo $PYTHONPATH
/usr/local/lib/python3.6/site-packages

$ pr /Users/mymacbook/.local/lib/python3.5/site-packages/homebrew.pth
import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")


附加信息:

在線某個地方還指定我應該擁有matplotlib最新版本。 我運行brew info matplotlib ,出現以下警告。 我按照指定的命令運行,但此警告仍然出現。 我不確定此問題是否與多multiarray問題有關。

==> Caveats
If you want to use the `wxagg` backend, do `brew install wxpython`.
This can be done even after the matplotlib install.
If you use system python (that comes - depending on the OS X version -
with older versions of numpy, scipy and matplotlib), you may need to
ensure that the brewed packages come earlier in Python's sys.path with:
  mkdir -p /Users/mymacbook/.local/lib/python3.5/site-packages
  echo 'import sys; sys.path.insert(1, "/usr/local/lib/python2.7/site-packages")' >> /Users/mymacbook/.local/lib/python3.5/site-packages/homebrew.pth

This formula installed .pth files to Homebrew's site-packages and your
Python isn't configured to process them, so you will not be able to
import the modules this formula installed. If you plan to develop
with these modules, please run:
  mkdir -p /Users/mymacbook/.local/lib/python3.5/site-packages
  echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/mymacbook/.local/lib/python3.5/site-packages/homebrew.pth


僅供參考,關於我的numpy軟件包。 它也具有與上述相同的警告。

$ brew info numpy
numpy: stable 1.13.3 (bottled), HEAD
Package for scientific computing with Python
http://www.numpy.org
/usr/local/Cellar/numpy/1.12.1 (442 files, 9.6MB)
  Poured from bottle on 2017-06-08 at 15:05:49
/usr/local/Cellar/numpy/1.13.0 (1,371 files, 29.0MB)
  Built from source on 2017-06-24 at 00:28:31 with: --with-python3
/usr/local/Cellar/numpy/1.13.3 (893 files, 21.8MB) *
  Poured from bottle on 2017-10-22 at 22:06:55


另一個問題(可能相關)....

$ pip search numpy
Traceback (most recent call last):
  File "/Users/tamtran/anaconda/bin/pip", line 7, in <module>
    from pip import main
  File "/Users/tamtran/anaconda/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
    from pip.utils import get_installed_distributions, get_prog.
.
.
.
AttributeError: '_NamespacePath' object has no attribute 'sort'

在此先感謝您的幫助! (很抱歉,信息過多,只是試圖提供盡可能多的上下文)(同樣,如果您可以為解決方案提供特定的commands ,將不勝感激)

在我的情況下,此問題是由sys.path導致,而在3.6之前先在2.7 site-packages目錄中查找。

sys.path ,您似乎遇到了類似的問題。 調用python3從Anaconda加載Python 3.5。 但是在2.7目錄之后會檢查所有Anaconda 3.5 site-package目錄。

# from OP sys.path
/usr/local/lib/python2.7/site-packages
/usr/local/Cellar/matplotlib/2.0.2/libexec/lib/python2.7/site-packages
/usr/local/Cellar/numpy/1.13.3/libexec/nose/lib/python2.7/site-packages
/Users/mymacbook/anaconda/lib/python3.5/site-packages # <-- should be before 2.7

^這就是導致問題的原因。

我嘗試了多種解決方案來解決此問題,包括擺脫.pth文件並重新路由sys.path腳本。 最終,我只是從2.7 site-packages刪除了numpy目錄,因為我不需要它,而嘗試精確地跟蹤sys.path構造方式並對其進行永久排序令我感到沮喪。

如果您不想成為極端用戶,請查看站點文檔,以准確跟蹤sys.path的組合方式。

嘗試在此處重新排列sys.path不會帶來幸福。

您無法混合搭配python 2和3的brew,conda和pip軟件包,並且結果可重復

為自己創造一個新鮮的conda環境

conda create -n tensorproject python ipython tensorflow <other pkgs>
source activate tensorflowproject

康達將為您管理您的依賴。 您可以conda安裝其他軟件包,並在conda-forge上找到非anaconda的軟件包。 當您需要更多功能時,可以將其安裝到該環境中。

請注意,當您創建像這樣的conda環境時,只有已知可以一起使用的軟件包才會被放置在站點軟件包中,而site.py將毫無奇怪。

注意:您可能還應該刪除PYTHONPATH環境變量。

編輯:graph_tool安裝graph_tool安裝頁面

確保使用相同的編譯器來編譯整個堆棧(Python,Boost等),否則可能會導致問題。

graph_tool的編譯器要求(下)與您的Anaconda構建(py35)不匹配。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM