在jupyter notebook运行matplotlib.pyplot内核挂掉

问题描述:

在Jupyter notebook中使用matplotlib绘图,此前好好的。突然有一天一运行plt.plot函数内核就会挂掉。查看jupyter notebook服务窗口的报错信息为

Kernel started: d65828cf-4958-43b7-8b4d-c23757f70824, name: python3 [W 08:43:10.941 NotebookApp] Got events for closed stream <zmq.eventloop.zmqstream.ZMQStream object at 0x0000021A2E2CAF08> [W 08:43:10.942 NotebookApp] Got events for closed stream <zmq.eventloop.zmqstream.ZMQStream object at 0x0000021A2E2CAF08> OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/. [I 08:43:16.661 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports WARNING:root:kernel d65828cf-4958-43b7-8b4d-c23757f70824 restarted

重装了matplotlib不能解决问题。 换一个虚拟环境没有同样的问题。

解决方法:

在虚拟环境中设置KMP_DUPLICATE_LIB_OK=TRUE。 具体方法为

激活虚拟环境

activate envi_name

设置环境变量

set KMP_DUPLICATE_LIB_OK=TRUE

退出虚拟环境
deactivate

重新激活虚拟环境

activate envi_name

查看环境变量

echo %KMP_DUPLICATE_LIB_OK%

结果显示为TRUE,则重启Jupyter notebook,问题解决。

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 解决matplotlib.pyplotJupyter Notebook中不显示图像问题可以按照以下步骤进行: 1. 首先,确保已经正确安装了matplotlib库。可以使用命令`pip install matplotlib`来安装最新的版本。 2. 导入matplotlib.pyplot并查看是否出现任何错误。如果没有错误,继续执行下一步。 3. 如果在终端或命令提示符中使用matplotlib模块时可以正常显示图像,但在Jupyter Notebook中无法显示图像,可能是由于Jupyter Notebook的设置问题。 4. 在代码的开头添加 `%matplotlib inline`,以确保在Jupyter Notebook中内联显示图像。这将告诉Jupyter Notebook在代码块的末尾自动显示matplotlib绘制的图像。 ``` import matplotlib.pyplot as plt %matplotlib inline ``` 5. 如果在执行代码后仍然无法显示图像,尝试使用`plt.show()`来手动显示图像。 ``` import matplotlib.pyplot as plt %matplotlib inline # 绘制图像 plt.plot(x, y) plt.show() ``` 6. 检查Jupyter Notebook内核是否在运行,并且没有发生任何错误。如果有错误,修复错误并重新启动Jupyter Notebook。 7. 确保Jupyter Notebook所用的Python环境与matplotlib的安装环境一致。如果使用了虚拟环境,请确保已将matplotlib正确安装在该环境中。 希望通过以上步骤能够解决matplotlib.pyplotJupyter Notebook中不显示图像问题。如果问题仍然存在,可以尝试在社区或论坛中寻求进一步的帮助。 ### 回答2: 解决matplotlib.pyplotJupyter Notebook中不显示图像的问题可以尝试以下几种解决方法。 1. 检查是否安装了matplotlib库和相关的依赖库。在终端或命令提示符中输入"pip list"或"conda list"命令,查看matplotlib和相关依赖库是否已安装。 2. 确保代码中包含正确的绘图语句并执行。例如,使用"plt.show()"语句显示图像,或在使用Jupyter Notebook时,使用"%matplotlib inline"命令启用内联绘图。 3. 检查是否存在其他的图像显示设置。有时候,Jupyter Notebook可能会在代码中显示图像之前或之后进行其他的图像显示操作,导致最终无法正确显示图像。可以尝试在代码的适当位置添加"plt.figure()"等语句,确保图像正常显示。 4. 检查Jupyter Notebook运行环境是否正常。有时候,由于Jupyter Notebook的问题,可能导致图像无法正常显示。可以尝试重新启动Jupyter Notebook,或者使用其他的Jupyter Notebook环境,如Google Colab等。 总之,要解决matplotlib.pyplotJupyter Notebook中不显示图像的问题,可以通过检查安装情况、确认代码正确性、调整图像显示设置和检查Jupyter Notebook环境等方式进行解决。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值