How do I change the terminal inside Visual Studio code to use the non-Rosetta one i.e. have it use the arm64 one?

Viewed 2259

I am new to python and am trying to run a python 2.7 script. Got pip for python 2.7 and installed a dependency of pyCrypto from the mac terminal shell.

The downloaded python script, I want to try, runs fine in the terminal app when I execute it using python2.

Now I open it in vscode and try to run the script in its terminal and I get

ImportError: dlopen(/Users/xxx/Library/Python/2.7/lib/python/site-packages/Crypto/Cipher/_DES3.so, 2): no suitable image found.  Did find:
        /Users/xxx/Library/Python/2.7/lib/python/site-packages/Crypto/Cipher/_DES3.so: mach-o, but wrong architecture
        /Users/xxx/Library/Python/2.7/lib/python/site-packages/Crypto/Cipher/_DES3.so: mach-o, but wrong architecture

When I run uname -m inside a vscode terminal(zsh) on an M1 Mac, I see an output of x86_64, implying the terminal is running under Rosetta and looking for the intel version of the library.

And when I run uname -m in the regular mac terminal app, I see arm64

How do I change the terminal inside vscode to use the non rosetta one? Or how do I get the script to run from within vscode?

2 Answers

I'm not familiar with VSCode, but you can manually force the chosen architecture slice of anything you launch with the arch command (see man arch).

If you have a script that you'd normally launch like:

./script.py

Then you can force either architecture like so:

arch -x86_64 ./script.py
arch -arm64 ./script.py

I have had issues with "forcing" the Universal binary to run under Rosetta 2, so you might have to download the Intel version and install it with a slightly modified name (e.g. VSCode (Intel)) so that they can co-exist side-by-side.

This will force the entire process tree to run under the emulation, which will take care of all your shells and debugging sessions underneath it to run the same (emulated) way. Please be aware of how that could interfere with pre-existing extensions.

Related