AttributeError:模块'matplotlib'在Visual Studio的jupyter-notebook上没有属性'get_data_path' [英] AttributeError: module 'matplotlib' has no attribute 'get_data_path' on Visual Studio's jupyter-notebook

查看:94
本文介绍了AttributeError:模块'matplotlib'在Visual Studio的jupyter-notebook上没有属性'get_data_path'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想在Visual Studio的jupyter-notebook上导入matplotlib.pyplot时,出现以下错误.

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'

但是,如果我在导航器的jupyter-notebook上尝试相同的代码,则不会出现此错误.所以我不明白为什么会出现此错误,因为两个笔记本都在安装了matplotlib 3.3.1版本的同一内核下运行.

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

推荐答案

我遇到了同样的问题,并通过使用以下顺序来解决该问题\

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

  • 使用终端定向到项目根文件夹
  • 假设您正在运行 conda 环境.因此,通过
    激活环境 conda激活环境名称
  • 运行python解释器: python 命令并检查天气matplotib已由安装\\
    import matplotlib
  • 运行 code 命令以在此目录中打开VScode.
  • 打开终端并检查天气环境是否已激活
  • 还要检查天气jupyter Ipython内核是否在同一环境下运行
  • 如果没有任何环境,则将其更改为特定的环境\
  • 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
  • also check weather jupyter Ipython kernel runs on the same environment
  • if any environment is not the one then, change it to a particular one\

这通常不会在 pip 环境中发生,因为VScode不会激活两个频道 [ pip conda ]或conda环境在大多数情况下会自动出现.

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.

这篇关于AttributeError:模块'matplotlib'在Visual Studio的jupyter-notebook上没有属性'get_data_path'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆