Search code examples
macostensorflowpycharmpytorchapple-m1

How can I run both TensorFlow and Torch on Mac M1 MacBook Pro?


I encounter some problems on my MacBook Pro M1. I thought it would be easier to start coding on it, apparently it's not a ML beast yet...

I need to use both PyTorch and TensorFlow on Python. I have installed TensorFlow 2.0 for Mac OS.

The problem is: TensorFlow won't work when you use a x86_64 terminal. (So it doesn't work with PyCharm). However, I can import TensorFlow 2.0 from an arm terminal. Paradoxically, PyTorch won't install on a arm terminal, only on a x86_64 terminal. So, on the same Python terminal, I'm not able to import both torch and TensorFlow 2.0.

Since HuggingFace transformers is crucial for me, and transformers needs both TensorFlow 2.0 and PyTorch, I need to go back on my old computer to code. I'm very disappointed!

Anyone successfully imported both PyTorch and TensorFlow on a Mac M1 device?

And does anyone know if there is a way to force PyCharm to use an arm terminal, so I can use TensorFlow 2.0 on PyCharm on my M1 MPB?

Thank you!


Solution

  • After some research, I found this answer: https://github.com/pytorch/pytorch/issues/48145 .

    So if someone tries to run both Tensorflow and Torch on Mac M1 with PyCharm Apple Silicon Version, here's how to proceed:

    Now you can open a PyCharm project with your freshly created virtual environment, and you'll be able to import both Tensorflow and Torch. However, a lot of librairies will be tricky to install like PyTorch...