1
1

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 3 years have passed since last update.

Homebrew でインストールした JupyterLab で pandas がインポートできない

Posted at

症状

Code セル

import pandas as pd

実行結果

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-ca154c91f1ef> in <module>
----> 1 import pandas as pd
      2 

ModuleNotFoundError: No module named 'pandas'

調査

JupyterLab のパスを調べる

Code セル

import sys
import pprint

pprint.pprint(sys.path)

実行結果

['/Users/oppara/sandbox/jupterlab',
 '/usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python37.zip',
 '/usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python3.7',
 '/usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python3.7/lib-dynload',
 '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
 '',
 '/usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python3.7/site-packages',
 '/usr/local/Cellar/jupyterlab/1.2.4/libexec/lib/python3.7/site-packages/IPython/extensions',
 '/Users/oppara/.ipython']

pandas のパスを確認

% pip3 show pandas
Name: pandas
Version: 1.0.1
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://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: 

原因

pandas がインストールされているパスが、JupyterLab のパスに含まれていない。

力技な対応

Code セル

import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')

import pandas as pd

その他の対応

Homebrew でなく、pip(pip3) でインストールした JupyterLab を使う

% brew uninstall jupyterlab
% pip3 install jupyterlab

pip でインストールした JupyterLab のパス

['/Users/oppara/sandbox/jupterlab',
 '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
 '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
 '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
 '',
 '/Users/oppara/Library/Python/3.7/lib/python/site-packages',
 '/usr/local/lib/python3.7/site-packages',
 '/usr/local/Cellar/protobuf/3.11.3/libexec/lib/python3.7/site-packages',
 '/usr/local/lib/python3.7/site-packages/IPython/extensions',
 '/Users/oppara/.ipython']

環境

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.3
BuildVersion:   19D7

% brew --version
Homebrew 2.2.5

% python3 -V
Python 3.7.6

参照

Jupyter Notebook: ModuleNotFoundError: No module named 'pandas' - Qiita

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?