7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pipでインストールしたはずのmoduleが実行されない

Posted at

pipでインストールしているはずのmoduleが実行されなくて困った時に確認することをメモしておく。

実行環境

  • python 2.7.10
  • MacOS10.10.5

今回はまった現象

>>> from scipy.stats import multivariate_normal
Import Error: cannot import name multivariate_normal

scipyのバージョンが古いのかと思い、調べて見ても最新(0.16.1)

$ pip list | grep scipy
scipy (0.16.1)

いろいろと確認してみた。

pipでmoduleの更新確認

update確認
$ pip install --upgrade scipy
Requirement already up-to-date: scipy in /usr/local/lib/python2.7/site-packages
Cleaning up...

python内部でのmodule参照先の確認

参照確認
$ python -c 'import scipy; print scipy.__file__'
/Library/Python/2.7/site-packages/scipy/__init__.pyc

pipのインストール先と違う?

$ ls /Library/Python/2.7/site-packages/site-packages | grep scipy
scipy
scipy-0.13.0-py2.7.egg-info

module参照pathの確認

$ python -c 'import sys; print sys.path'
['', '/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/Library/Python/2.7/site-packages/Django-1.7.4-py2.7.egg', '/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages', '/Library/Python/2.7/site-packages/setuptools-8.2.1-py2.7.egg', '/usr/local/lib/python2.7/site-packages']

結果

自分のpython環境にはsite-packagesが2つあり片方のsite-packagesはpipでのインストール先となっているsite-packagesより優先的に読み込まれるらしい。そして、優先のsite-packagesにいつの間にか古いscipyをインストールしてしまっていたことが原因。
とりあえずpipで管理していないライブラリを消して解決。
そういえばDjango環境を作った時にこの辺の設定をいじったようななかったような。

7
8
1

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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?