0

I'm having trouble getting matplotlib to work on pycharm on my M1 Mac. I am running the following code and getting the following error message. The goal is to open a miniseed file and plot the seismic data in it.

Code:

from obspy import read
import matplotlib.pyplot as plt

# Open MiniSEED file
st = read('/Users/petertsirushkin/Downloads/OO.HYS14..HDH.2020.092.00.00.00.000-2020.093.00.00.00.000.miniseed')

trace = st[0]
times = trace.times()
amplitudes = trace.data

# Plot the waveform
plt.plot(times, amplitudes)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.title('Seismic Waveform')
plt.show()

Error Message

ImportError: dlopen(/Users/petertsirushkin/PycharmProjects/pythonProject1/venv/lib/python3.11/site-packages/matplotlib/_c_internal_utils.cpython-311-darwin.so, 0x0002): tried: '/Users/petertsirushkin/PycharmProjects/pythonProject1/venv/lib/python3.11/site-packages/matplotlib/_c_internal_utils.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/petertsirushkin/PycharmProjects/pythonProject1/venv/lib/python3.11/site-packages/matplotlib/_c_internal_utils.cpython-311-darwin.so' (no such file), '/Users/petertsirushkin/PycharmProjects/pythonProject1/venv/lib/python3.11/site-packages/matplotlib/_c_internal_utils.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I've tried installing an ARM64 version of matplotlib but I'm not sure if it's organized correctly in my mac's file structure and if pycharm is looking at it. When I do pip show matplotlib in the command line I get the following information:

Name: matplotlib
Version: 3.7.1
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: /Users/petertsirushkin/anaconda3/lib/python3.11/site-packages
Requires: contourpy, cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by: seaborn

And it seems like I have matplotlib 3.7.2 as the version that Python Interpreter sees in my pycharm project:

enter image description here

As for the software versions I am running: OSX Ventura 13.1; pycharm community edition 2022.2.5 build #PC-222.4554.11, built on March 15 2023 Runtime version: 17.0.6+7-b469.82 x82_64 VM: OpenJdk 64-Bit Server VM by JetBrains s.r.o

jared
  • 4,165
  • 1
  • 8
  • 31
Peter
  • 3
  • 1
  • Your Python is running in Rosetta. If Python is launched from an x86_64 process, then it too will run as x86_64. Try prefixing the command with `arch -arm64`. – Siguza Jul 18 '23 at 03:56
  • You cannot mix architectures on same binary. So the main binary (python) and all libraries (so also all compiled modules) must share same architecture (intel or arm). In your case, you are mixing both. The answer explain you how do to it (so using conda with multiple architectures), unfortunately without explanations. Ideally you should get all binaries from arm64, to use full power. – Giacomo Catenazzi Jul 18 '23 at 10:05
  • @GiacomoCatenazzi so should i just uninstall python and all asociated libraries and try to download arm64 version of each? If so, do you think you could send me links to where i can find the arm64 version of each? This is what i though the issue was so i tried to download only arm64 versions of each – Peter Jul 20 '23 at 02:48
  • @Peter: no, and possibly you cannot remove all python (In past one old version of python were provided by Apple, for internal stuffs. If you are using conda, you can have different environments with different interpreters AND with different architectures. Check https://stackoverflow.com/questions/71515117/how-to-set-up-a-conda-osx-64-environment-on-arm-mac and https://stackoverflow.com/questions/65415996/how-to-specify-the-architecture-or-platform-for-a-new-conda-environment-apple (and possibly other links). – Giacomo Catenazzi Jul 20 '23 at 06:41
  • Note: sometime just creating a new environment will help (newer version may have better support: many people are using Apple silicon) – Giacomo Catenazzi Jul 20 '23 at 06:42

1 Answers1

0

These kinds of compatibility issues are complicated. There are two methods that I suggest you try after uninstalling matplotlib.

  1. Use conda instead. Get conda if you don't already have it and run conda install matplotlib.
  2. If that doesn't work, try forcing pip to build up from sources with pip install --no-binary matplotlib.
jared
  • 4,165
  • 1
  • 8
  • 31
Shiran Yuan
  • 105
  • 5