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

11,056

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.

Share:
11,056
Ermite
Author by

Ermite

Updated on July 21, 2022

Comments

  • Ermite
    Ermite almost 2 years

    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. :)

  • Alessio
    Alessio over 3 years
    Welcome to Stack Overflow! This was posted as an answer, but it does not attempt to answer the question. It should possibly be an edit or a comment.
  • JGBM
    JGBM over 3 years
    I know, but I do not have a reputation to comment, and it might provide some insight as I found this question because I had the same problem and solved it this way.
  • Jolbas
    Jolbas over 3 years
    If you could explain a bit more it might be more helpful
  • JGBM
    JGBM over 3 years
    I had that error when using a kernel, which was not up-to-date (but in which I had already used matplotlib a few months/a year ago). When I used one that it was up-to-date, the problem disappear. (This is not an actual solution, but it solved the problem for me and may be an hint for someone else).