'pycharm debug on m1 mac fails with: `pydevd_cython_darwin_310_64.cpython-310-darwin.so incompatible architecture`
I just upgraded to pycharm 2022.01 and got an error when debugging a python program using m1 mac:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_cython_wrapper.py", line 8, in <module>
from _pydevd_bundle_ext import pydevd_cython as mod
ModuleNotFoundError: No module named '_pydevd_bundle_ext'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_cython_wrapper.py", line 11, in <module>
from _pydevd_bundle import pydevd_cython as mod
ImportError: cannot import name 'pydevd_cython' from '_pydevd_bundle' (/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 55, in <module>
from _pydevd_bundle.pydevd_trace_dispatch import (
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_trace_dispatch.py", line 42, in <module>
from _pydevd_bundle.pydevd_cython_wrapper import trace_dispatch as _trace_dispatch, global_cache_skips, global_cache_frame_skips, fix_top_level_trace_and_get_trace_func
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_cython_wrapper.py", line 35, in <module>
mod = getattr(__import__(check_name), mod_name)
ImportError: dlopen(/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_cython_darwin_310_64.cpython-310-darwin.so, 0x0002): tried: '/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_cython_darwin_310_64.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))
Process finished with exit code 1
I installed the right version of pycharm. Couldn't find the right .so version on pypi.
How can I fix this? Is it possible to recompile pydevd for arm64e?
Solution 1:[1]
Managed to rebuild pydevd that comes with PyCharm:
Rebuild the binaries
Make sure you have cython installed to update and compile the cython sources:
sudo pip3 install cython
export PYTHONPATH=/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev:$PYTHONPATH
cd /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev
python3.10 build_tools/build.py
After that, debugging in PyCharm worked fine.
Check the binaries
What the rebuild apparently did:
- removed all
_pydevd_bundle/pydevd_cython_darwin_*.sofiles - created only
_pydevd_bundle/pydevd_cython.cpython-310-darwin.so
Use the file command to confirm the binary has the architecture required for new M1 (Apple Silicon) chips:
file _pydevd_bundle/pydevd_cython.cpython-310-darwin.so`
It should output required architecture for M1 like arm64 below:
_pydevd_bundle/pydevd_cython.cpython-310-darwin.so: Mach-O 64-bit bundle arm64
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hc_dev |
