尽管已安装,但无法导入 matplotlib

时间:2021-05-27 05:30:44

标签: python linux matplotlib python-3.9 arch

我使用的是 arch linux,直到最近我才犯了使用 pip 全局安装东西的错误。我试图删除与 pacman 未跟踪的 Python 相关的所有内容。然后我删除了 pip。

我知道 pip 的 --user 标志,但最后我使用相同的一组基本包,我宁愿使用我的包管理器全局安装。

为了调试一些代码,我最近需要调试符号,这些符号引导我自己编译 python。之后,我用 pacman 重新安装了它。

目前安装的是 python2 和 3,而 python 指向 v3。

如果我启动 REPL 并运行 help("modules") 我得到:

>>> help("modules")

Please wait a moment while I gather a list of all available modules...

/usr/lib/python3.9/site-packages/IPython/kernel/__init__.py:12: ShimWarning: The `IPython.kernel` package has been deprecated since IPython 4.0.You should import from ipykernel or jupyter_client instead.
  warn("The `IPython.kernel` package has been deprecated since IPython 4.0."
/usr/lib/python3.9/site-packages/lutris/gui/dialogs/__init__.py:10: PyGIWarning: Gtk was imported without specifying a version first. Use gi.require_version('Gtk', '3.0') before import to ensure that the right version gets loaded.
  from gi.repository import GObject, Gtk, WebKit2, GLib
/usr/lib/python3.9/pkgutil.py:108: VisibleDeprecationWarning: zmq.eventloop.minitornado is deprecated in pyzmq 14.0 and will be removed.
    Install tornado itself to use zmq with the tornado IOLoop.
    
  yield from walk_packages(path, info.name+'.', onerror)

然后是包含 matplotlibmatplotlib_inline 的模块列表。

如果我尝试在 REPL 中导入它,我会得到:

Python 3.9.5 (default, May 24 2021, 12:50:35) 
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pascal/matplotlib.py", line 1, in <module>
    import matplotlib.path as mpath
ModuleNotFoundError: No module named 'matplotlib.path'; 'matplotlib' is not a package

现在在写这篇文章时,当我在我的主目录中打开 REPL 时,我确实能够导入它一次,但我无法复制它。

此外 /usr/lib/python3.9/site-packages 包含

matplotlib/
matplotlib_inline/
matplotlib-3.4.1-py3.9.egg-info/  
matplotlib_inline-0.1.2-py3.9.egg-info/
matplotlib-3.4.1-py3.9-nspkg.pth 

pacman -Q 列表

python-matplotlib 3.4.1-2
python-matplotlib-inline 0.1.2-1

还有搜索路径(在 REPL 中运行)是:

>>> import sys
>>> sys.path
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/<user>/.local/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages']

0 个答案:

没有答案