matplotlib/mplcairo

Circular import error

mlwyne opened this issue · 2 comments

Hello,

I am attempting to use mplcairo, but I am getting a circular import error.

My code looks like this:

import matplotlib.pyplot as plt
import matplotlib
import mplcairo

# import matplotlib
print('Default backend: ' + matplotlib.get_backend()) 
matplotlib.use("module://mplcairo.macosx")
print('Backend is now ' + matplotlib.get_backend())

And the error I'm getting is this:

Traceback (most recent call last):
  File "/my/file/path", line 14, in <module>
    import mplcairo
  File "/opt/homebrew/lib/python3.11/site-packages/mplcairo/__init__.py", line 27, in <module>
    from . import _mplcairo
ImportError: cannot import name '_mplcairo' from partially initialized module 'mplcairo' (most likely due to a circular import) (/opt/homebrew/lib/python3.11/site-packages/mplcairo/__init__.py)

At first, I was getting this error when I tried running with a normal pip3 install mplcairo so I followed the steps in this link to do a manual build and install of the wheel. The wheel that I built was mplcairo-0.5.post33+g68b4558-cp39-cp39-macosx_11_0_arm64.whl , which gave me an unsupported platform error, but I renamed it to mplcairo-0.5.post33+g68b4558-py39-none-any.whl to see if it would run then (I have an M1 Mac on 14.1.1). The build seemed successful but I am yet again getting the circular import error.

Let me know how I'd be able to fix this and run mplcairo. Thanks!

You seem to have a python3.9 wheel and a python3.11 install (per the homebrew path you give) mixed up?

Awesome, cleaning up my python installs fixed the issue and it's working beautifully now. Thank you so much!