无法从“matplotlib”导入名称“_png”

eimct9ow  于 2022-11-30  发布在  其他
关注(0)|答案(8)|浏览(178)

我想使用matplotlib而不是kivy_garden. graph。实际上,我尝试了this code来检查它是否适合我。我在安装matplotlib时遇到了一些问题,但我成功地(或没有)完成了安装。
当我启动代码时,我得到了from matplotlib import _png ImportError: cannot import name '_png' from 'matplotlib' (D:\PyCharmProjects\kivyApp\venv\lib\site-packages\matplotlib\__init__.py),我重新安装了matplotlib和pip,尝试了matplotlib的另一个版本,我不知道为什么它不适合我。我有Python 3.7.5pip 20.2.4matplotlib 3.3.3

7hiiyaii

7hiiyaii1#

恢复到matplotlib版本3.0.2对我来说不起作用,但在3.1.3中起作用了。

python -m pip uninstall matplotlib
pip install matplotlib==3.1.3

Python 3.8.2语言

2cmtqfgy

2cmtqfgy2#

我在Google Colab中遇到了这个问题,但无法解决它。我找到的简单解决方案是安装稳定版本pip install -U matplotlib,然后重新启动运行时,它就工作了。

gcmastyq

gcmastyq3#

我在PyCharm* 中从终端执行了py -m pip uninstall matplotlibpy -m pip install matplotlib --version=3.0.2 * 之后的命令。cmd和git bash中的相同命令不起作用。

jdzmm42g

jdzmm42g4#

如果您使用的是Linux发行版,则问题出在matplotlib的安装中。
卸载当前版本:pip卸载matplotlib
正确的安装可在以下位置找到:https://matplotlib.org/stable/users/installing.html
请从下面为您的发行版选择正确的代码:
Linux软件包管理器如果您使用的是Linux发行版附带的Python版本,您可以通过软件包管理器安装Matplotlib,例如:
Debian / Ubuntu:python3-matplotlib中的函数
Fedora:下载并安装python3-matplotlib
Red Hat:红帽软件包
Arch:sudo pacman -S python-matplotlib搜索引擎帮助中心
在这之后,它应该工作得很好。

6psbrbz9

6psbrbz95#

你也可以评论这个导入的行:)(对我来说是C:\Users{username}.kivy\garden\garden.matplotlib\backend_kivy.py,第256行)但是我不知道它将来会带来什么问题。

vohkndzv

vohkndzv6#

由于这个bug存在了这么多年,我放弃了waiting for the kivy-garden community to fix it。所以当部署我的kivy软件时,我也发布了下面的快速修复程序。它会自动找到文件并注解掉那一行。

from pathlib import Path
# Join user's home directory with Garden's file path
file = Path.home().joinpath('.kivy/garden/garden.matplotlib/backend_kivy.py')
# Read file
lines = []
with open(file, 'r') as f:
    for line in f:
        lines.append(line)
# Write file
with open(file, 'w') as f:
    for line in lines:
        if line.startswith('from matplotlib import _png'):
            # comment out this troublesome line
            line = '#' + line
        f.write(line)
xdnvmnnf

xdnvmnnf7#

我在Google Colab中也遇到了这个问题
尝试这个pip安装matplotlib==3.1.3在Google Colab中为我工作

kq0g1dla

kq0g1dla8#

仅导入matplotlib库

pip install matplotlib==3.1.3

并且,该版本

相关问题