#実行するコード pyplot_label_title.py
import matplotlib.pyplot as plt #エラーの行 price = [200,300,400,500,600] count = [30,29,25,28,26] plt.plot(price,count) plt.title("count - price") plt.xlabel("price") plt.ylabel("count") plt.show()
とある入門書付属のコードです。
エラー内容は以下の通りです。
Traceback (most recent call last): File "C:\Users\myname\workspace\pyplot_label_title.py", line 1, in <module> import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'
#詳細
・コマンドプロンプトでPythonを起動した状態ではimportに成功します
・pip show matplotlib を実行すると以下の通りです。
Name: matplotlib Version: 3.1.1 Summary: Python plotting package Home-page: https://matplotlib.org Author: John D. Hunter, Michael Droettboom Author-email: matplotlib-users@python.org License: PSF Location: c:\users\myname\anaconda3\lib\site-packages Requires: cycler, kiwisolver, pyparsing, python-dateutil, numpy Required-by: seaborn, scikit-image
##環境
Python 3.8
(Python を起動するとPython 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 とでる)
##やってみたこと(3/24追加)
仮想環境を変えてみた
(base) C:\Users\myname\workspace>conda activate test1 (test1) C:\Users\myname\workspace>conda list # packages in environment at C:\Users\myname\Anaconda3\envs\test1: # # Name Version Build Channel blas 1.0 mkl ca-certificates 2020.1.1 0 certifi 2019.11.28 py37_1 cycler 0.10.0 py37_0 freetype 2.9.1 ha9979f8_1 icc_rt 2019.0.0 h0cc432a_1 icu 58.2 ha66f8fd_1 intel-openmp 2020.0 166 jpeg 9b hb83a4c4_2 kiwisolver 1.1.0 py37ha925a31_0 libpng 1.6.37 h2a8f88b_0 matplotlib 3.1.3 py37_0 matplotlib-base 3.1.3 py37h64f37c6_0 mkl 2020.0 166 mkl-service 2.3.0 py37hb782905_0 mkl_fft 1.0.15 py37h14836fe_0 mkl_random 1.1.0 py37h675688f_0 numpy 1.18.1 py37h93ca92e_0 numpy-base 1.18.1 py37hc3f5095_1 openssl 1.1.1e he774522_0 pip 20.0.2 py37_1 pyparsing 2.4.6 py_0 pyqt 5.9.2 py37h6538335_2 python 3.7.6 h60c2a47_2 python-dateutil 2.8.1 py_0 qt 5.9.7 vc14h73c81de_0 setuptools 46.1.1 py37_0 sip 4.19.8 py37h6538335_0 six 1.14.0 py37_0 sqlite 3.31.1 he774522_0 tornado 6.0.4 py37he774522_1 vc 14.1 h0510ff6_4 vs2015_runtime 14.16.27012 hf0eaf9b_1 wheel 0.34.2 py37_0 wincertstore 0.2 py37_0 zlib 1.2.11 h62dcd97_3 (test1) C:\Users\myname\workspace>pyplot_label_title.py Traceback (most recent call last): File "C:\Users\myname\workspace\Python3_sample\Python3_sample\Part3\Chapter14\Section14-1\pyplot_label_title.py", line 1, in <module> import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'
######sys.pathを実行
実行したコード
import sys print(sys.path)
結果
(base) C:\Users\myname\workspace>sys.py ['C:\Users\myname\workspace', 'C:\Users\myname\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\myname\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\myname\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\myname\AppData\Local\Programs\Python\Python37', 'C:\Users\myname\AppData\Local\Programs\Python\Python37\lib\site-packages']
(これが原因でしょうか?)
Pythonを起動した状態で
(base) C:\Users\myname\workspace>python Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', 'C:\Users\myname\Anaconda3\python37.zip' , 'C:\Users\myname\Anaconda3\DLLs', 'C:\Users\myname\Anaconda3\lib' , 'C:\Users\myname\Anaconda3', 'C:\Users\myname\Anaconda3\lib\site-packages' , 'C:\Users\myname\Anaconda3\lib\site-packages\win32', 'C:\Users\shungo\Anaconda3\lib\site-packages\win32\lib' , 'C:\Users\myname\Anaconda3\lib\site-packages\Pythonwin']
回答2件
あなたの回答
tips
プレビュー