错误:在Mac的jupyter笔记本中导入matplotlib.pyplot as plt。

15 浏览
0 Comments

错误:在Mac的jupyter笔记本中导入matplotlib.pyplot as plt。

在Jupyter笔记本中,我想导入matplotlib.pyplot,但是遇到了以下错误。我尝试按照这个网站(https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python)的说明添加matplotlibrc文件,但是失败了。错误信息如下:

----------------------------------------------------------------

运行时错误 Traceback (most recent call last)

in ()

1 import pandas as pd

----> 2 import matplotlib.pyplot as plt

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/pyplot.py in ()

112

113 from matplotlib.backends import pylab_setup

--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()

115

116 _IP_REGISTERED = None

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/backends/__init__.py in pylab_setup()

30 # imports. 0 means only perform absolute imports.

31 backend_mod = __import__(backend_name,

---> 32 globals(),locals(),[backend_name],0)

33

34 # Things we pull in from all backends

/Users/Nima/miniconda3/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in ()

22

23 import matplotlib

---> 24 from matplotlib.backends import _macosx

25

26

运行时错误: Python未作为框架安装。如果Python未作为框架安装,Mac OS X后端将无法正常工作。请参阅Python文档以获取有关在Mac OS X上安装Python作为框架的更多信息。请重新安装Python作为框架,或尝试其他后端。如果您在虚拟环境中使用Matplotlib,请参阅Matplotlib FAQ中的“在虚拟环境中使用Matplotlib”

0
0 Comments

这个问题的出现原因是在安装matplotlib时出现了访问权限错误。解决方法是使用`--user`选项或检查权限。

**错误原因:**

这个问题发生在使用命令`pip install --upgrade jupyter matplotlib`安装matplotlib时。错误提示显示访问被拒绝,具体的错误信息是`[WinError 5] Access is denied`。这意味着当前用户没有足够的权限来访问安装目录。

**解决方法:**

为了解决该问题,有两个解决方法可供选择:

**方法一:使用--user选项**

使用`--user`选项来安装matplotlib。这样安装的matplotlib将仅对当前用户可用,而不需要管理员权限。

运行以下命令来安装matplotlib:

pip install --upgrade --user jupyter matplotlib

**方法二:检查权限**

如果你是使用管理员权限运行的命令提示符或终端,但仍然出现访问权限错误,那么可能是安装目录的权限设置有问题。你可以通过以下步骤来检查并更改权限:

1. 打开安装目录的文件资源管理器(如Windows资源管理器)。

2. 导航到`c:\users\nadee\anaconda3\lib\site-packages\matplotlib`目录。

3. 右键单击`_backend_agg.cp37-win_amd64.pyd`文件,选择“属性”。

4. 在“属性”对话框中,切换到“安全”选项卡。

5. 确保当前用户具有“完全控制”权限。如果没有,点击“编辑”按钮来更改权限。

6. 确认更改后,点击“应用”和“确定”来保存更改。

7. 重新运行安装命令。

这些解决方法应该可以解决在安装matplotlib时出现的访问权限错误。如果问题仍然存在,请尝试使用其他方法或查阅matplotlib的官方文档获取更多帮助。

0
0 Comments

最近我也遇到了同样的问题。这个问题在最新版本的jupytermatplotlib中似乎已经修复了,而且在我系统上运行以下命令后,在运行jupyter notebook时也解决了这个错误:

(env)$ pip install --upgrade jupyter matplotlib

这是我在虚拟环境中使用Python 2.7.10的软件包版本:

matplotlib==2.0.0
jupyter==1.0.0
jupyter-client==5.0.0
jupyter-console==5.1.0
jupyter-core==4.3.0
ipython==5.2.2
ipython-genutils==0.1.0

对于旧版本,有其他解决方法:

https://stackoverflow.com/a/35107136/2113258,

https://stackoverflow.com/a/21789908/2113258

0