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

ImportError: cannot import name '_mplcairo' from partially initialized module 'mplcairo' #49

Closed
AgilentGCMS opened this issue Sep 13, 2023 · 5 comments

Comments

@AgilentGCMS
Copy link

I recently installed mplcairo 0.5 on MacOS with pip install mplcairo. However, when I try to import it, I get:

In [1]: import mplcairo
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import mplcairo

File ~/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mplcairo/__init__.py:27
     23     _load_symbols()
     25 import matplotlib as mpl
---> 27 from . import _mplcairo
     28 from ._mplcairo import antialias_t, operator_t, get_options, set_options
     30 __all__ = [
     31     "antialias_t", "operator_t",
     32     "get_options", "set_options",
     33     "get_raw_buffer",
     34 ]

ImportError: cannot import name '_mplcairo' from partially initialized module 'mplcairo' (most likely due to a circular import) (/Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mplcairo/__init__.py)

I am using python 3.11.5.

@anntzer
Copy link
Collaborator

anntzer commented Sep 13, 2023

What are the contents of ~/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mplcairo/?
Any relevant output if you uninstall mplcairo and reinstall it with pip install -v mplcairo?

@AgilentGCMS
Copy link
Author

$ ls -l ~/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/mplcairo/
total 64
-rw-r--r--  1 sbasu1 staff  3234 2023 Sep 13 09:18:58 __init__.py
drwxr-xr-x 14 sbasu1 staff   448 2023 Sep 13 09:18:58 __pycache__
-rw-r--r--  1 sbasu1 staff   664 2023 Sep 13 09:18:58 _backports.py
-rw-r--r--  1 sbasu1 staff  2422 2023 Sep 13 09:18:58 _util.py
-rw-r--r--  1 sbasu1 staff   155 2023 Sep 13 09:18:58 _version.py
-rw-r--r--  1 sbasu1 staff 17664 2023 Sep 13 09:18:58 base.py
-rw-r--r--  1 sbasu1 staff  1373 2023 Sep 13 09:18:58 gtk.py
-rw-r--r--  1 sbasu1 staff  1486 2023 Sep 13 09:18:58 gtk_native.py
-rw-r--r--  1 sbasu1 staff   605 2023 Sep 13 09:18:58 macosx.py
-rw-r--r--  1 sbasu1 staff  2131 2023 Sep 13 09:18:58 multipage.py
-rw-r--r--  1 sbasu1 staff  2219 2023 Sep 13 09:18:58 qt.py
-rw-r--r--  1 sbasu1 staff   815 2023 Sep 13 09:18:58 tk.py
-rw-r--r--  1 sbasu1 staff  1385 2023 Sep 13 09:18:58 wx.py
$ pip install -v mplcairo
Using pip 23.2.1 from /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
Collecting mplcairo
  Using cached mplcairo-0.5-cp311-cp311-macosx_13_0_x86_64.whl
Requirement already satisfied: matplotlib>=2.2 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from mplcairo) (3.7.2)
Requirement already satisfied: pillow in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from mplcairo) (9.5.0)
Requirement already satisfied: pycairo>=1.16.0 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from mplcairo) (1.23.0)
Requirement already satisfied: contourpy>=1.0.1 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (1.0.7)
Requirement already satisfied: cycler>=0.10 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (4.42.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (1.4.5)
Requirement already satisfied: numpy>=1.20 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (1.25.2)
Requirement already satisfied: packaging>=20.0 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (23.1)
Requirement already satisfied: pyparsing>=2.3.1 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (3.1.1)
Requirement already satisfied: python-dateutil>=2.7 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from matplotlib>=2.2->mplcairo) (2.8.2)
Requirement already satisfied: six>=1.5 in /Users/sbasu1/packages/macports/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (from python-dateutil>=2.7->matplotlib>=2.2->mplcairo) (1.16.0)
Installing collected packages: mplcairo
Successfully installed mplcairo-0.5

@anntzer
Copy link
Collaborator

anntzer commented Sep 14, 2023

Ugh, clearly something went wrong with the compilation.
Try again uninstalling and pip install --no-cache-dir -v mplcairo (to force a recompilation)? Although now I do suspect that this is a fallout from pypa/wheel#566 and I'll basically need to make a new release (which is unlikely to happen in the coming days, at least); in that case the most likely to work for you is to just install from git HEAD (where the above issue with wheel has been fixed): pip install -v git+https://github.com/anntzer/mplcairo.

@AgilentGCMS
Copy link
Author

The first suggestion, pip install --no-cache-dir -v mplcairo, did not solve the problem. However, pulling from the git head with pip install -v git+https://github.com/anntzer/mplcairo solved it. Thanks!

@AgilentGCMS
Copy link
Author

FYI, this bug is still there. I just installed mplcairo on a new computer, and import failed with this error. The fix, as described here, worked.

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

No branches or pull requests

2 participants