web-dev-qa-db-ja.com

RuntimeError:APIバージョン0xcに対してコンパイルされたモジュールですが、numpyのこのバージョンは0xbです

機械学習を学習しようとしていますが、以下のエラーを解決できません。

[私の環境]

  • Mac High Sierra 10.13.2
  • Python3.4.5
  • ナンピー1.13.3

[コマンド]

$ python3 -c "import jupyter, matplotlib, numpy, pandas, scipy, sklearn"

[エラー]

RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb
Traceback (most recent call last):
  File "/Users/uekyo/ml/env/lib/python3.4/site-packages/pandas/__init__.py", line 26, in <module>
    from pandas._libs import (hashtable as _hashtable,
  File "/Users/uekyo/ml/env/lib/python3.4/site-packages/pandas/_libs/__init__.py", line 4, in <module>
    from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
  File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib
ImportError: numpy.core.multiarray failed to import

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/uekyo/ml/env/lib/python3.4/site-packages/pandas/__init__.py", line 35, in <module>
    "the C extensions first.".format(module))
ImportError: C extension: numpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.

[試したこと]

私はnumpyが間違っていることを理解しました。だから私は以下のものを試しましたが、エラーはまだ表示されます。

〜1〜

Sudo mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_old

〜2〜

pip3 uninstall numpy
pip3 install numpy  -I

ありがとう。

11
uekyo

これは、TensorFlowによって引っ張られたpandas version higher than 0.21.0numpy version 1.13.3がうまくいっているためではないようです。最後に修正した方法を次に示します。

# ipython
Python 2.7.6 (default, Nov 23 2017, 15:49:48)
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import tensorflow as tf
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xb

In [2]: !pip install pandas==0.21.0
Collecting pandas==0.21.0
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request
has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server
to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve
 this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLC
ontext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to f
ail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest
/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading pandas-0.21.0-cp27-cp27mu-manylinux1_x86_64.whl (24.3MB)
    100% |################################| 24.3MB 52kB/s
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python2.7/dist-packages (from pandas==0.21.0)
Requirement already satisfied: numpy>=1.9.0 in /usr/local/lib/python2.7/dist-packages (from pandas==0.21.0)
Requirement already satisfied: python-dateutil in /usr/local/lib/python2.7/dist-packages (from pandas==0.21.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python2.7/dist-packages (from python-dateutil->pandas==0.21.0)
Installing collected packages: pandas
  Found existing installation: pandas 0.21.1
    Uninstalling pandas-0.21.1:
      Successfully uninstalled pandas-0.21.1
Successfully installed pandas-0.21.0

In [3]: del tf

In [4]: import tensorflow as tf
8

おそらく、numpyのバージョンが低すぎることが原因です。これは私の問題を解決しました:

pip3 install "numpy == 1.15.0" --user 

conda installは現在numpyバージョン1.13.1しか持っていないため解決できませんが、選択したミラーサイトが最新ではない可能性があります

5
cloudscomputes

同じ問題がありました。アナコンダを使用している場合は、単に入力します

conda更新テンソルフロー

これで問題が解決するはずです。

0
Piyush jain