'How to conditionally install a Python dependency only if Apple Silicon Rosetta 2 is being used?

I want to pip install a certain package when using Apple Silicon + Rosetta 2 and another package otherwise. What's the best way to do this?

One approach I thought of is this. Pip supports environment markers that let you conditionally install dependencies like so.

atomac==1.1.0; sys_platform == 'darwin'

Anyone know if it’s possible and how to use sysctl as an environment marker? My use case is that sysctl -in sysctl.proc_translated returns 1 on Apple Silicon + Rosetta 2 and 0 otherwise. On other platforms like Ubuntu, sysctl might not be available as a command.

Another approach is to have two different requirements.txt files and run a script that selects the appropriate one based on return value of sysctl -in sysctl.proc_translated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source