Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kivy-garden.matplotlib "cannot import name '_png' from 'matplotlib'" #69

Closed
nooninm opened this issue Oct 30, 2020 · 16 comments · Fixed by #75
Closed

kivy-garden.matplotlib "cannot import name '_png' from 'matplotlib'" #69

nooninm opened this issue Oct 30, 2020 · 16 comments · Fixed by #75

Comments

@nooninm
Copy link

nooninm commented Oct 30, 2020

All five files below fail the same way. I discovered it following along in a Samuel POS course.
.kivy\garden\garden.matplotlib
backend_kivy.py
backend_kivyagg.py

.kivy\garden\garden.matplotlib\examples
test_backend.py
test_events.py
test_plt.py

All five files give the same error. Namely,
ImportError: cannot import name '_png' from 'matplotlib'

I have Python 3.8 and also a venv with 3.6.8. Same results.

@matham matham transferred this issue from kivy-garden/garden Oct 30, 2020
@nooninm
Copy link
Author

nooninm commented Oct 30, 2020

My video course seems to not need _png, so my solution for now is to simply comment out the line trying to import it. In my case it is line 256 of garden.matplotlib\backend_kivy.py like so:
#from matplotlib import _png

@dev-param
Copy link

did not work
same error here

@Mnikley
Copy link

Mnikley commented Jan 16, 2021

Same error since upgrading to Kivy 2.0.0 and matplotlib 3.3.3

@fuddyduddy
Copy link

fuddyduddy commented Jan 18, 2021

My video course seems to not need _png, so my solution for now is to simply comment out the line trying to import it. In my case it is line 256 of garden.matplotlib\backend_kivy.py like so:
#from matplotlib import _png

Tried this fix, but raised another problem.
My python version is 3.8.3,
Kivy version is 1.11.1 and
matplotlib 3.3.1
ImportError: cannot import name 'FigureCanvansKivyAgg' from 'kivy.garden.matplotlib.backend_kivyagg' (C:\Users\user\.kivy\garden\garden.matplotlib\backend_kivyagg.py)
Not yet tried the degrade matplotlib method, i hope this bug can be fixed soon.

@v15shm
Copy link

v15shm commented Jan 19, 2021

I am facing the same issue
certifi==2020.12.5
chardet==4.0.0
cycler==0.10.0
docutils==0.16
idna==2.10
Kivy==2.0.0
kivy-deps.angle==0.3.0
kivy-deps.glew==0.3.0
kivy-deps.gstreamer==0.3.1
kivy-deps.sdl2==0.3.1
Kivy-Garden==0.1.4
kiwisolver==1.3.1
matplotlib==3.3.3
numpy==1.19.5
pandas==1.2.0
Pillow==8.1.0
Pygments==2.7.4
pymongo==3.11.2
pyparsing==2.4.7
pypiwin32==223
python-dateutil==2.8.1
pytz==2020.5
pywin32==300
requests==2.25.1
six==1.15.0
urllib3==1.26.2

@badubies
Copy link

badubies commented Feb 8, 2021

bump

@ChromaticIsobar
Copy link

I did a little bit of tests, this seems to affect usage with matplotlib versions >=3.3.0.
You could try downgrading your matplotlib versions until maintainers don't address this issue

pip install -U "matplotlib<3.3.0"

@ChromaticIsobar
Copy link

Also, this seems a duplicate of issues #58 and #67
Although this issue's title better captures what's the problem

@SalvishGoomanee
Copy link

from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg

Everything was installed properly and I have no errors being picked up in the PyCharm IDE.
However upon running just the my .py file which includes the above. I get the error:

ImportError: cannot import name '_png' from 'matplotlib'

I have matplotlib version = latest, I tried to downgrade to version = 3.1.3 but it could not get install on my machine. I don't know why.

The downgrading option is really not optimal as I need latest version of mpl for other applications.

Thank you for suggesting some ways out of this!

@SalvishGoomanee
Copy link

SalvishGoomanee commented Aug 23, 2021

UPDATE:

Commenting out from matplotlib import _png and from from matplotlib import _path as suggested in #58 (and #67) allows one to run a script with the line from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg.

However upon testing it with a simple program like the one in the answer in https://stackoverflow.com/questions/44905416/how-to-get-started-use-matplotlib-in-kivy.

I get a bunch of errors:

line 623, in __getitem__ return dict.__getitem__(self, key) KeyError: 'datapath'

I hope this is clear and hope to get some advice on this! Many thanks!

UPDATE bis: So downgraded to 3.2.2 as @ChromaticIsobar suggested and it works but the depreciation isn't optimal so any other options, would be great! :)

@djiometsa
Copy link

I have a problem importing the _png from matplotlib while working with python and kivy.
After entering : from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg in python file and running it, i receive the following Import Error. Please does some one have an idea how to solve the problem?

ImportError: cannot import name 'png' from 'matplotlib' (C:\Users\djiometsa-jiotio\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\matplotlib_init.py)

I have the following versions of modules installed:
Kivy==2.0.0
kivy-deps.angle==0.3.0
kivy-deps.glew==0.3.0
kivy-deps.sdl2==0.3.1
Kivy-Garden==0.1.4
kivy-garden.graph==0.4.0
kiwisolver==1.3.2
matplotlib==3.2.2

Thanks for your proposals

@Mnikley
Copy link

Mnikley commented Nov 22, 2021

@djiometsa what i did was the following:

  1. navigate to C:\Users\USERNAME.kivy\garden\garden.matplotlib
  2. Copy backend_kivy.py and backend_kivyagg.py to your local repository
  3. Comment the following import in backend_kivy.py: # from matplotlib import _png
  4. Import the kivy backend via your local, copied and commented .py files (e.g. from backend_kivy import FigureCanvasKivy)

i cant test it right now but this should get you on the right track for a temporary fix

@djiometsa
Copy link

It is still not working for me. After i did the fourth instruction, i had another Importerror

4. from backend_kivy import FigureCanvasKivy

ImportError: cannot import name 'FigureCanvasKivy' from partially initialized module 'backend_kivy' (most likely due to a circular import)

@Mnikley
Copy link

Mnikley commented Nov 24, 2021

For me this works. Minimal reproducible example:

from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from backend_kivy import FigureCanvasKivy

class TestApp(App):
    def build(self):
        root = BoxLayout(orientation='vertical')
        lbl = Label(text="[b]Some FigureCanvasKivy attributes:[/b]\n" + "\n".join(dir(FigureCanvasKivy)[-20:]), markup=True)
        root.add_widget(lbl)
        return root

if __name__ == '__main__':
    TestApp().run()

Source files as .zip

@SBS-EREHM
Copy link

SBS-EREHM commented Jan 1, 2022

For me this works. Minimal reproducible example:

from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from backend_kivy import FigureCanvasKivy

Holy Crap, Batman (I mean @Mnikley). That works!

WTF with matplotlib _png?

And why is Kivy rated as #1 in "The 6 Best Python GUI Frameworks for Developers"?

@gustavofelicidade
Copy link

Guys, downgrading to 3.2.2 works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.