导入matplotlib.pyplot在ubuntu上挂起

2ledvvac  于 2022-11-02  发布在  其他
关注(0)|答案(1)|浏览(164)

我在Windows 10机器上的WSL 2中使用Ubuntu发行版中的Python3安装。
在过去的两个月里,我没有写那么多代码。现在我重新开始,面临着以下问题:
以下代码挂起约2分钟:

import matplotlib.pyplot

2分钟后,我得到了以下输出:

Traceback (most recent call last):
  File "a.py", line 5, in <module>
    import matplotlib.pyplot as plt 
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2469, in <module>
    switch_backend(rcParams["backend"])
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 277, in switch_backend
    class backend_mod(matplotlib.backend_bases._Backend):
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/pyplot.py", line 278, in backend_mod
    locals().update(vars(importlib.import_module(backend_name)))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/backends/backend_qt4agg.py", line 6, in <module>
    from .backend_qt5agg import (
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/backends/backend_qt5agg.py", line 11, in <module>
    from .backend_qt5 import (
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/backends/backend_qt5.py", line 13, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/backends/qt_editor/figureoptions.py", line 11, in <module>
    from matplotlib.backends.qt_compat import QtGui
  File "/home/markus/.local/lib/python3.8/site-packages/matplotlib/backends/qt_compat.py", line 179, in <module>
    raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding

此问题已在此处描述:import matplotlib.pyplot hangs
但这些建议的解决方案并不奏效。
我接着跑

sudo pip install --upgrade matplotlib

这很有帮助,因为导入命令现在可以工作了,但执行它仍然需要2分钟!
你知道,为什么这个命令要花这么多时间吗?

nkhmeac6

nkhmeac61#

卸载并重新安装Matlplotlib没有帮助。
卸载并重新安装python 3. X没有帮助。
在Windows设置中重置Ubuntu安装是有效的,例如,请参见此处:
https://askubuntu.com/questions/761360/how-do-i-reset-my-installation-of-ubuntu-on-windows

相关问题