LoginSignup
11
4

More than 5 years have passed since last update.

macOS Xでmglearnがimportできなかったときの話

Posted at

mac OS:OS X Capitan 10.11.6
Python:3.6

初のQiita投稿ながらだいぶニッチな内容。
機械学習の勉強がてら環境構築をしていて、タイトルの問題に直面。

状況

$ pip install mglearn
でインストールが完了したかと思いきや、

terminal
import mglearn

で呼び出すと

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
...
RuntimeError: Python is not installed as a framework.
...

とか何とか出てしまいエラー。

対応

自分の環境では主に3つ対応が必要だった。

1.環境パス設定

下記の内容をそのまま実行。
参考:pip install したパッケージをimport できないときの対応

自分の場合は参考URLと違い、下記のパスを通した。
~/.pyenv/versions/3.6.4/lib/python3.6/site-packages

2.imageioのinstall

よしパスが通った、ということでいざjupyter notebookで一式importしてみると今度はimreadで引っかかる。

jupyter_notebook
ImportError: cannot import name 'imread'

どうやらscipy1.0以降ではimreadはscipy.miscではなくimageioから参照してほしいとのことらしい。

参考:scipy.misc.imread

$ pip install imageio
ということでimageioのインストール。
これでimreadでエラーを吐くことがなくなった。

3.mglearn配下のファイルを書き換え

今度こそこれで実行出来る、と思いきやmglearn配下のpyファイルでscipy.misc経由でimreadを呼ぶファイルが2つある模様。

~animal_tree.py/~interactive_tree.py
from scipy.misc import imread

~animal_tree.py/~interactive_tree.py
from imageio import imread

bak作成後にimageioからの呼び出しに書き換えて、対応完了。
試行錯誤の段階で不要なものinstallしすぎた。。

11
4
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
11
4