kivy-garden / garden.matplotlib

Matplotlib backends using kivy
MIT License
104 stars 50 forks source link

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

Closed nooninm closed 2 years ago

nooninm commented 4 years ago

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.

nooninm commented 4 years ago

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 commented 3 years ago

did not work same error here

Mnikley commented 3 years ago

Same error since upgrading to Kivy 2.0.0 and matplotlib 3.3.3

fuddyduddy commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

bump

ChromaticIsobar commented 3 years ago

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 commented 3 years ago

Also, this seems a duplicate of issues https://github.com/kivy-garden/garden.matplotlib/issues/58 and https://github.com/kivy-garden/garden.matplotlib/issues/67 Although this issue's title better captures what's the problem

SalvishGoomanee commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

Guys, downgrading to 3.2.2 works for me