# PythonでModuleNotFoundError: No module named 'XXX'が出た場合の対処法
PandasをインストールしたはずなのにModuleNotFoundErrorがでた
Traceback (most recent call last): File "main.py", line 2, in <module> import pandas ModuleNotFoundError: No module named 'pandas'
pip show <インストールモジュール名> でインストールが正しくされているかの確認。
$ pip show pandas Name: pandas Version: 0.24.1 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: /home/XX/.local/lib/python2.7/site-packages Requires: numpy, pytz, python-dateutil
Locationがpython2.7のところに入っていた。 python3で動かしていたのでModuleNotFoundErrorが出てしまった。 https://web.plus-idea.net/2017/05/python-import-error-no-module-name/
ずっとpip install <インストールモジュール名>
でインストールしていたのが問題だったみたい。
なので以下でpip3をインストール。
$ sudo apt install python3-pip $ pip3 --version pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6) $ pip3 install pandas $ pip3 show pandas Name: pandas Version: 0.24.1 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: /home/XX/.local/lib/python3.6/site-packages Requires: pytz, python-dateutil, numpy
無事にpandasがインストールできた。 https://www.python.jp/install/ubuntu/pip.html