LoginSignup
8
6

More than 5 years have passed since last update.

python numpy が importエラーになる

Last updated at Posted at 2019-04-09

centos:7のdockerコンテナ上で python2.7 の numpy をインストールし
importすると下記のエラーが発生

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "numpy/__init__.py", line 142, in <module>
    from . import core
  File "numpy/core/__init__.py", line 91, in <module>
    raise ImportError(msg.format(path))
ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

「古いnumpyもあるけど、どっちだ!?」的なエラー。

ちなみにdockerfileはこんな感じ

# OS
FROM centos:7

# install tools
RUN yum update -y \
&& yum install -y epel-release 

RUN yum install -y python-pip \
                   python-tables \
RUN pip install --upgrade pip 
RUN pip install numpy --ignore-installed \

numpyをインストールしないと1.7.1と古いため追加でインストール。
インストールそのものはエラーなし。
気のせいか、以前はエラーにはなっていなかった気がする。

最初に古いnumpyをアンインストールしようとすると下記のエラー。

Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

「このnumpyはdistutils(Pythonビルトインの配布ユーティリティ)なので消せないぜ!」
的なエラー。

pip install --update numpy をやっても、distutilsを理由にバージョンは変わらず。

Installing collected packages: numpy
  Found existing installation: numpy 1.7.1
Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

virtualenvなどの案もちらほらあるが、特定のコンテナアプリ利用なので
強制的にnumpyを削除する荒技

rm -rf /usr/lib64/python2.7/site-packages/numpy*

その後にinstallすれば正常にimportもできた

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6