前提・実現したいこと
ここに質問の内容を詳しく書いてください。
「Pythonではじめる機械学習」を使って勉強中にmglearnをインポートしようとしてもできません
発生している問題・エラーメッセージ
Requirement already satisfied: mglearn in /anaconda3/lib/python3.7/site-packages (0.1.7)
Requirement already satisfied: pillow in /anaconda3/lib/python3.7/site-packages (from mglearn) (5.2.0)
Requirement already satisfied: imageio in /anaconda3/lib/python3.7/site-packages (from mglearn) (2.4.1)
Requirement already satisfied: cycler in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.10.0)
Requirement already satisfied: matplotlib in /anaconda3/lib/python3.7/site-packages (from mglearn) (2.2.3)
Requirement already satisfied: scikit-learn in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.19.2)
Requirement already satisfied: numpy in /anaconda3/lib/python3.7/site-packages (from mglearn) (1.15.1)
Requirement already satisfied: pandas in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.23.4)
Requirement already satisfied: six in /anaconda3/lib/python3.7/site-packages (from cycler->mglearn) (1.11.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2.2.0)
Requirement already satisfied: python-dateutil>=2.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2.7.3)
Requirement already satisfied: pytz in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2018.5)
Requirement already satisfied: kiwisolver>=1.0.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (1.0.1)
Requirement already satisfied: setuptools in /anaconda3/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->mglearn) (40.2.0)
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-22-694e3943fc29> in <module>()
1 get_ipython().system(' pip install mglearn')
----> 2 import mglearn
3
4 import numpy as np
5 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'mglearn'
エラーメッセージ
該当のソースコード
! pip install mglearn
import mglearn
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from IPython.display import display
%ma
ソースコード
試したこと
ネットで調べてpillowのインストール
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
mglearn のインストールはしましたか?
!pip install mglearn をjupiter notebook で入力しました
自分の環境で試しましたが、Notebook で !pip install mglearn としたあと、import mglearn で問題なく import できましたね。
やはり何度試してもダメでした
mac book pro 使ってます。
mglearn をインポートする前に他のソフトウェアをインポートしないといけないとかありますか?
Windows や Linux で試しましたが、とくに pip install だけで動きましたね。
Requirement already satisfied: mglearn in /anaconda3/lib/python3.7/site-packages (0.1.7) とあるので、インストールされているようにも見えるのですが、import できないということは違う Python 環境にインストールされてしまったのでしょうかね?
import sys
site_packages = next(p for p in sys.path if 'site-packages' in p)
print(site_packages)
以上のコードを実行した結果が以下のようになっていますか?
<適当なパス>/anaconda3/lib/python3.7/site-packages
もしかしたら他の環境でインストールしたのかもしれません
その場合どうすればいいでしょうか?
コードを実行しました。
anaconda3/lib/python3.7/site-packages
と出ました。
他の環境も何個か試しで使ってたんで
Notebook を使ってる環境で pip install mglearn ですが、今どの環境で notebook を動かしているのか等理解する必要があります。
conda info -e で環境一覧を確認できます。
Anaconda の環境の切り替え等はいろいろ解説記事があると思うので、そちらを参照ください
話が少し変わるのですが、pip install mglearn はどこで入力したらいいですか?
anaconda prompt ですか?
基本的には入れたい環境に source activate <環境名> で切り替えて、そこで pip install mglearn ですね
pip install mglearn と打つと
Requirement already satisfied: mglearn in /anaconda3/lib/python3.7/site-packages (0.1.7)
Requirement already satisfied: imageio in /anaconda3/lib/python3.7/site-packages (from mglearn) (2.4.1)
Requirement already satisfied: pillow in /anaconda3/lib/python3.7/site-packages (from mglearn) (5.2.0)
Requirement already satisfied: matplotlib in /anaconda3/lib/python3.7/site-packages (from mglearn) (2.2.3)
Requirement already satisfied: numpy in /anaconda3/lib/python3.7/site-packages (from mglearn) (1.15.1)
Requirement already satisfied: pandas in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.23.4)
Requirement already satisfied: scikit-learn in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.19.2)
Requirement already satisfied: cycler in /anaconda3/lib/python3.7/site-packages (from mglearn) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2.2.0)
Requirement already satisfied: python-dateutil>=2.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2.7.3)
Requirement already satisfied: pytz in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (2018.5)
Requirement already satisfied: six>=1.10 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (1.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /anaconda3/lib/python3.7/site-packages (from matplotlib->mglearn) (1.0.1)
Requirement already satisfied: setuptools in /anaconda3/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib->mglearn) (40.2.0)
と返してきます
コンソールでそのAnaconda環境に切り替え、 python インタプリタを python コマンドで起動して、import mglearn とするとどうなりますか?
本当に申し訳ないんですが、ド素人なので切り替えるというのも正直どこからどうすればいいかわからないです。申し訳ないです
source acitvate <環境名> です
とりあえず公式ドキュメントやWebの情報で Anaconda の使い方について勉強したほうが良いと思います。
https://minus9d.hatenablog.com/entry/2016/01/29/235916
Anaconda は複数のバージョンの Python を使い分けたり、有名なモジュールが同梱されてて便利ですが、今どの環境で作業しているのか等を意識できないと、パッケージをインストールしたはずなのに使えないという今回の自体になります
あなたの回答
tips
プレビュー