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

Mac OS, No module named 'matplotlib.backends.backend_macosx' error #2651

Closed
ioctl-user opened this issue Jan 17, 2024 · 11 comments
Closed

Mac OS, No module named 'matplotlib.backends.backend_macosx' error #2651

ioctl-user opened this issue Jan 17, 2024 · 11 comments
Assignees
Milestone

Comments

@ioctl-user
Copy link

I am running Mac OS 10.15 on x86_64.
Python 3.10 installed via brew, Nuitka installed via pip3.10 , matplotlib 3.8.2 also installed via pip3.10.

python -m nuitka --version

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named nuitka

python3.10 -m nuitka --version

1.9.7
Commercial: None
Python: 3.10.13 (main, Jan 16 2024, 09:57:43) [Clang 12.0.0 (clang-1200.0.32.29)]
Flavor: Homebrew Python
Executable: /usr/local/Cellar/python@3.10/3.10.13_1/bin/python3.10
OS: Darwin
Arch: x86_64
Version C compiler: /usr/bin/clang (clang 12.0.0).

cat 1.py

from matplotlib import pyplot as plt

y = [0, 1, 2, 3]

plt.plot(y, color="red", markersize=1, linestyle='-')
plt.show()

nuitka3 --standalone ./1.py

Nuitka-Options:INFO: Used command line options: --standalone ./1.py
Nuitka:INFO: Starting Python compilation with Nuitka '1.9.7' on Python '3.10' commercial grade 'not installed'.
Nuitka-Plugins:INFO: anti-bloat: Not including '_bisect' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation.
Nuitka-Plugins:INFO: anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation.
Nuitka-Plugins:INFO: anti-bloat: Not including 'PIL.ImageQt' automatically in order to avoid bloat, but this may cause: PIL will not be able to create Qt image objects.
Nuitka-Plugins:INFO: matplotlib: Using configuration file or default backend 'MacOSX'.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.    
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: clang (clang 12.0.0).
Nuitka-Scons:INFO: Backend linking program with 305 files (no progress information available for this stage).
Nuitka-Scons:INFO: Compiled 305 C files using ccache.
Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache hit': 304
Nuitka-Scons:INFO: Cached C files (using ccache) with result 'cache miss': 1
Nuitka-Plugins:INFO: matplotlib: Included 182 data files due to package data for 'matplotlib.
Nuitka-Plugins:INFO: matplotlib: Included data file 'matplotlib/mpl-data/matplotlibrc' due to updated matplotlib config file with backend to use.
Nuitka:INFO: Keeping build directory '1.build'.                                 
Nuitka:INFO: Created binary that runs on macOS 10.15 (x86_64) or higher.
Nuitka:INFO: Successfully created '1.dist/1.bin'.

./1.dist/1.bin

Traceback (most recent call last):
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/1.py", line 5, in <module>
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 3575, in plot
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 2525, in gca
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 1000, in gcf
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 934, in figure
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 464, in new_figure_manager
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 441, in _warn_if_gui_out_of_main_thread
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 280, in _get_backend_mod
  File "/Users/build/Downloads/nuitka-matplot-test/1.dist/matplotlib/pyplot.py", line 342, in switch_backend
  File "importlib.py", line 126, in import_module
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'matplotlib.backends.backend_macosx'

@kayhayen

This comment was marked as resolved.

@kayhayen kayhayen added the needs_example User input needed label Jan 19, 2024
@kayhayen kayhayen self-assigned this Jan 19, 2024
@ioctl-user

This comment was marked as resolved.

@kayhayen
Copy link
Member

I clearly have reading issues, I apologize.

@kayhayen
Copy link
Member

It seems the CI test only doing import matplotlib doesn't trigger it. I reproduced it just now with version 3.8.1 which I happen to still have installed. Pretty sure some version some time worked, but this should be easy. Probably a Nuitka regression, since I believe we now ask code what backend is used.

@kayhayen
Copy link
Member

So what happens is that the default backend on macos was not included, but only the Qt ones, if you used PySide or PyQt, as many people do. The dependent was easy to add. Then the C code is badly implemented, sort of:

line 78, in _single_shot_timer
  File "/Users/hayen/repos/Py2C/MatplotlibUsing.dist/matplotlib/backend_bases.py", line 1150, in start
RuntimeError: _on_timer should be a Python method

At least it tests its assumption and properly error exits where other things sometimes just segfault. That required a plugin change for the matplotlib plugin to not compile those functions, and then it works for me.

@kayhayen
Copy link
Member

Thanks for your report, this is fixed on the factory branch, which is a development version under rapid development. You can try it out by going here: https://nuitka.net/doc/factory.html

Feedback if this is working is very welcome, just please do not share plans of doing it, but rather confirmations or denials of it working.

@kayhayen kayhayen added bug factory For issues fixed in factory only excellent_report and removed needs_example User input needed labels Jan 19, 2024
@kayhayen kayhayen added this to the 2.0 milestone Jan 19, 2024
@kayhayen
Copy link
Member

There will be no 1.9 hotfixes anymore, so this is part of 2.0 release which is delayed due to flu I seem to have caught, but should happen within 1-2 weeks for sure.

@ioctl-user
Copy link
Author

Fix tested - working.

p.s. According to the github repo history your PC clock is late for about 2 days.

@kayhayen
Copy link
Member

That's WSL2 for you, during suspend, the system time doesn't move. I don't bother to correct it a lot, but I agree it's not nice.

@kayhayen
Copy link
Member

This is now on develop branch and will be part of the 2.0 release.

@kayhayen kayhayen reopened this Jan 22, 2024
@kayhayen kayhayen added develop For issues fixed in develop only and removed factory For issues fixed in factory only labels Jan 22, 2024
@kayhayen
Copy link
Member

This is part of the stable release 2.0 that I just made.

@kayhayen kayhayen removed the develop For issues fixed in develop only label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants