6

I have a new MacBook with the Apple M1 chipset. To install tensorflow, I follow the instructions here, i.e., installing tensorflow-metal and tensorflow-macos instead of the normal tensorflow package.

While this works fine, it means that I can't run the typical pip install -r requirements.txt as long as we have tensorflow in the requirements.txt. If we instead include tensorflow-macos, it'll lead to problems for non-M1 or even non-macOS users.

Our library must work on all platforms. Is there a generic install command that installs the correct TensorFlow version depending on whether the computer is a M1 Mac or not? So that we can use a single requirements.txt for everyone?

Or if that's not possible, can we pass some flag/option, e.g., pip install -r requirements.txt --m1 to install some variation? What's the simplest and most elegant solution here?

stefanbschneider
  • 5,460
  • 8
  • 50
  • 88

1 Answers1

6

According to this post Is there a way to have a conditional requirements.txt file for my Python application based on platform?

You can use conditionals on your requirements.txt, thus

tensorflow==2.8.0; sys_platform != 'darwin' or platform_machine != 'arm64'
tensorflow-macos==2.8.0; sys_platform == 'darwin' and platform_machine == 'arm64'
stefanbschneider
  • 5,460
  • 8
  • 50
  • 88
calmar
  • 1,930
  • 1
  • 14
  • 15