I occasionally like to use python from within org-mode in emacs? However, I've recently switched from intel architecture to m1 and this isn't working very well.
The pydantic module imports fine from my system python - but when I try to import it from within by editor python for some reason seems to be picking the wrong architecture.
From within emacs:
#+begin_src python :results output
import sys
print(sys.executable)
import pydantic
#+end_src
: /Library/Developer/CommandLineTools/usr/bin/python3
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
ImportError: dlopen(/Users/tom/Library/Python/3.9/lib/python/site-packages/pydantic/__init__.cpython-39-darwin.so, 0x0002): tried: '/Users/tom/Library/Python/3.9/lib/python/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/tom/Library/Python/3.9/lib/python/site-packages/pydantic/__init__.cpython-39-darwin.so' (no such file), '/Users/tom/Library/Python/3.9/lib/python/site-packages/pydantic/__init__.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))
[ Babel evaluation exited with code 1 ]
From a terminal, everything works fine:
python3
Python 3.9.6 (default, Mar 10 2023, 20:16:38)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
FileNotFoundError: [Errno 2] No such file or directory: '/Users/USER/.pythonrc.py'
>>> import sys
>>> print(sys.executable)
/Library/Developer/CommandLineTools/usr/bin/python3
>>> import pydantic
>>>
(Note that the python executable is the same)
I did some digging and within my editor platform.processor()
is returning i386 while from a python shell it is returning arm
, which is confusing.
Why is the processor wrong from within my editor?
My suspicion is that it's something to do with some sort of path be it the system path, the library path, or python's path
Approaches tried
- This question: [https://stackoverflow.com/questions/72308682/mach-o-file-but-is-an-incompatible-architecture-have-x86-64-need-arm64e] seems like it might be relevant?
platform
is implemented in python. Looking at the source code is callingos.uname()
directly and this seems to be lying about the architecture in my editor
#+begin_src python :results output
import os
print(os.uname())
#+end_src
#+RESULTS:
: posix.uname_result(sysname='Darwin', nodename='Danielas-MacBook-Air.local', release='22.4.0', version='Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103', machine='x86_64')
os.uname
appears to be a builtin and I assume that it is implemented in C which makes it difficult to debug... but hoping that the shell uname
commands works in the same way as os.uname
it looks like uname -a
is lying as well.
#+begin_src shell :results output
uname -a
#+end_src
#+RESULTS:
: Darwin computer.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:41 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8103 x86_64
I'm suspicious that some sort of emulation is going on...