LoginSignup
21
10

More than 5 years have passed since last update.

Jupyter Notebook: ModuleNotFoundError: No module named 'pandas'

Posted at

Jupyter Notebookで「ModuleNotFoundError: No module named 'pandas'」のエラーになるときは、モジュールのパスを確認して、正しい場所にpandasをインストールしよう。

症状

pip install pandasでpandasをインストールしたが、Jupyter Notebookでpandasがインポートできないエラーが発生する:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-6-e0409205a3ad> in <module>
----> 1 import pandas

ModuleNotFoundError: No module named 'pandas'

原因

Jupyter Notebookのモジュールのパスを調べる:

SlowTest.png

上の結果を見ると、Jupyter NotebookのモジュールのパスはPython3のものになっていることが分かる。

参考: jupyter notebookで、なぜかimportが通らない問題 - Qiita

今度はpipで入れたpandasのパスを調べると、Python2のものになっている。

$ pip show pandas
Name: pandas
Version: 0.24.2
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author: None
Author-email: None
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires: python-dateutil, numpy, pytz
Required-by:

対処法

この場合Python3で動いているので、pip3でpandasを入れ直す。

pip3 install pandas

pandasのパスを確認すると、Python3のパスにインストールされていることが分かる:

$ pip3 show pandas
Name: pandas
Version: 0.24.2
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author: None
Author-email: None
License: BSD
Location: /usr/local/lib/python3.7/site-packages
Requires: numpy, pytz, python-dateutil
Required-by:
21
10
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
21
10