Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: module 'matplotlib' has no attribute 'get_data_path' on Visual Studio's jupyter-notebook

I get the following error when I want to import matplotlib.pyplot on the Visual Studio's jupyter-notebook.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
 in 
----> 1 import matplotlib.pyplot as plt

~/miniconda3/envs/firstSteps/lib/python3.8/site-packages/matplotlib/__init__.py in 
    903 # triggering resolution of _auto_backend_sentinel.
    904 rcParamsDefault = _rc_params_in_file(
--> 905     cbook._get_data_path("matplotlibrc"),
    906     # Strip leading comment.
    907     transform=lambda line: line[1:] if line.startswith("#") else line,

~/.local/lib/python3.8/site-packages/matplotlib/cbook/__init__.py in _get_data_path(*args)

AttributeError: module 'matplotlib' has no attribute 'get_data_path'

But I don't have this error if I try the same code on the navigator's jupyter-notebook. So I don't understand why I get this error since both notebook are running under the same kernel which have the matplotlib 3.3.1 version installed on.

I would be grateful if someone can give me any enlightenment. :)

like image 609
Ermite Avatar asked Sep 10 '20 09:09

Ermite


2 Answers

I had the same problem because I was using the wrong python kernel. I had that problem when using the standard python kernel, but not when using a virtual env (which is what I usually use).

like image 81
JGBM Avatar answered Nov 17 '22 18:11

JGBM


I had this same problem and solve it by using the following sequence \

  • use terminal to direct to project root folder
  • Suppose you are running conda environment. so, activate the environment by
    conda activate env-name
  • run python interpreter : python command and check weather matplotib has installed by\
    import matplotlib
  • run code . command to open VScode in this directory.
  • open terminal and check weather enviromnet has activated enter image description here
  • also check weather jupyter Ipython kernel runs on the same environment enter image description here
  • if any environment is not the one then, change it to a particular one\

this won't happen in the pip environment usually, because VScode does not activate two channels [pip, conda] or conda environment automatically most of the times.

like image 2
nipun Avatar answered Nov 17 '22 18:11

nipun