Last week I switch from using Intel-based MacBook laptop (x86 architecture) to the one with Apple M1 (ARM64 architecture).
Recently Mathias Kemeter shared one approach of running hdbcli
on an Apple M1 Chip: creating a copy of a terminal app that starts using Rosetta.
A look at arch
command
I tried an alternative approach, that I would like to share here. It does not involve making a copy of the terminal application, but instead using arch
command.
As man arch
explains:
By default, the operating system will select the architecture that most closely matches the processor type. … The
arch
command can be used to alter the operating system’s normal selection order.The
arch
command with no arguments, displays the machine’s architecture type.
Let’s run the command without any parameters on a new laptop with an Apple chip. It should return arm64
value.
To run a command that supports x86_64
translation mode, you can execute:
/usr/bin/arch -arch x86_64 <command>
One more helpful command will be sysctl
to display, if a process is native or translated.
sysctl sysctl.proc_translated
/usr/bin/arch -arch x86_64 sysctl sysctl.proc_translated
A command or a binary you are running needs to support a given architecture as can be checked using file /path/to/binary
:
file $(which sysctl)
file $(which zsh)
Interestingly, MacOS default’s Python is a universal library…
file $(which python3)
python3 -V
arch -arch x86_64 python3 -V
…which Python installed with conda
is ARM64-only:
file $(which python)
python -V
arch -arch x86_64 python -V
Attempt to install hdbcli
using pip
on Apple silicon
If I try to install hdbcli
using pip
today (with no “universal” version of HDBCLI for Apple M1 available yet), then I get:
ERROR: Could not find a version that satisfies the requirement hdbcli (from versions: none)
ERROR: No matching distribution found for hdbcli
And what about the Miniconda?
Let us create a separate myhana
Conda’s environment…
conda create -n myhana python=3.9
conda activate myhana
Still the same.
Start a shell as the x86_64 process
Let’s start a shell with x86_64
compatible architecture…
arch -x86_64 zsh
export PS1='x86$ '
…and check the architecture set for the session.
arch
uname -m
🤔 I must admit this
i386
vsx86_64
is still confusing me. I will appreciate, if you share your explanation in comments, should you know why these two values are different.
Install hdbcli
in x86_64 process
Now that we are in the x86_64 translated process, let’s try installing hdbcli
using pip
.
python3 -m pip install hdbcli
python3 -m pip show hdbcli
And what about Miniconda environment?
Unfortunately it does not work.
I assume, it is because it got arm64-compatible binary of Python only — as we have checked above. And I have not found a way yet to install universal binary of Python into a conda’s environment yet. Have you?
Bonus: Create a profile in a terminal application for an x86 translated mode
To streamline invoking a shell in an x86 translated mode you can create a separate profile.
I am using iTerm2 application, so this is how my setup looks like.
- Make a copy of the Default profile and called it “Rosetta Shell”,
- Change Command setting from “Login Shell” to “Command” with the value
/usr/bin/arch -x86_64 /bin/zs
.
As always, please share your ideas and feedback in comments below!