1

iTerm2 can be scripted with Python

When I run Python REPL or Python script through iTerm2 Scripting menu on Apple Sillicon architecture (M2 in my case) it terminates with following error:

Bad CPU type

like in this example stacktrace:

2-3, 2:43:17.371 PM: /opt/homebrew/bin/zsh -c /Applications/iTerm.app/Contents/Resources/it2_api_wrapper.sh /Users/zxaos/.config/iterm2/AppSupport/iterm2env-3.7/versions/3.7.9/bin/python3 /Users/zxaos/.config/iterm2/AppSupport/Scripts/AutoLaunch/iTerm-DarkLight.py
12-3, 2:43:17.381 PM: + unset PYTHONPATH
12-3, 2:43:17.381 PM: + export PYTHONUNBUFFERED=1
12-3, 2:43:17.381 PM: + PYTHONUNBUFFERED=1
12-3, 2:43:17.381 PM: + /Users/zxaos/.config/iterm2/AppSupport/iterm2env-3.7/versions/3.7.9/bin/python3 /Users/zxaos/.config/iterm2/AppSupport/Scripts/AutoLaunch/iTerm-DarkLight.py
12-3, 2:43:17.381 PM: /Applications/iTerm.app/Contents/Resources/it2_api_wrapper.sh: line 6: /Users/zxaos/.config/iterm2/AppSupport/iterm2env-3.7/versions/3.7.9/bin/python3: Bad CPU type in executable
12-3, 2:43:17.382 PM: 
12-3, 2:43:17.382 PM: ** Script exited with status 126 **

How to solve it?

0

1 Answer 1

0

Problem is that Python included with iTerm2 is on x86 CPU architecture, but you have ARM CPU (Apple Sillicon or aarm64 architecture). You probably don't have Rosetta2 (Intel x86 emulation) installed.

  1. Open 'Terminal'
  2. Type softwareupdate --install-rosetta --agree-to-license
  3. Run (Enter)
11
  • A much better answer would be to install a native copy of Python. Commented Mar 21, 2023 at 16:55
  • 1
    This is the second of your questions you have self-answered with the same answer. Starting to feel a bit spammy.... Commented Mar 21, 2023 at 17:09
  • @AndyGriffiths Not spammy at all. This is how i find out about the problem. The second one is more generic because it's about how to install Rosetta through CLI. Both problems seems to me uncovered here on Stackexachange.com and even when you google it. This is why I made this twice. If you question me see my profile... Commented Mar 22, 2023 at 15:21
  • 1
    @MarcWilson the issue is scripting iTerm itself shich the author of iTerm admist is a problem - not running python in iTerm whioch works with no problems. The issue is that iTerm as a good ~//mac app bundles python - unfortunately only the intel version
    – mmmmmm
    Commented Mar 23, 2023 at 16:18
  • 4
    The CLI installation process for Rosetta2 is widely documented online also. All that aside, a lot of this could have been avoided with a clearer question in the first place. Only now, with all the extra information you've added about the iTerm2 in-built Python and scripting against iTerm's own API does it make sense. Commented Mar 23, 2023 at 19:51

Not the answer you're looking for? Browse other questions tagged .