Installing Pytorch on M1 Macbook?

I haven’t been able to install Pytorch. When I try using pip3, I get this error due to building wheel for Numpy:

ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly

When I use the Apple version of NumPy that Tensorflow released, I need to use a virtual env. So I activate that env and run the pip3 install command and get this error:

ERROR: Command errored out with exit status 1:

1 Like


Is there more information with this error?
I don’t think we have M1 binaries yet but building from source should work on master from what I can see. And if not, please report that so we can make sure to fix it.

Yes ,installing from source worked. Is there a way I can also install torchvision?

Since there is no binary, I guess you can also install it from source the same way.
If you encounter any issues with that, do report an issue on the torchvision repo!

Sorry, this isn’t my forte. How do I install torchvision from source?
Edit: Never mind, found the repo. Thanks for the help!


Ah, it seems Pytorch didn’t install fully from source. I have the arm64 NumPy, but when I run Pytorch code that includes torch.from_numpy(), I get the following error:

RuntimeError: PyTorch was compiled without NumPy support

Are you sure that your numpy version was properly detected when torch was compiling?

I’m not sure. I installed the numpy into the base Conda env and had that activated

You may install tensorflow first by following instructions GitHub - apple/tensorflow_macos: TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.. This step should solve the NumPy issue.
I followed instructions from How to install TensorFlow and NumPy on Apple Silicon (M1) - YouTube and could get tensorflow installed.
To install Pytorch with pip3, I enabled the terminal to run with Rosetta 2. For that, you need to right-click on the terminal app in Applications, then select ‘Get Info’ and select the option ‘Open using Rosetta’.
After enabling the option, launching terminal would automatically run all subsequent commands in Rosetta 2 and therefore commands that work for Intel-based Macs would work for M1 Mac. So you can simply install pytorch with pip3 install torch .
I believe running it in Rosetta would not get you the optimum performance for the platform but it may help you to get started with at least using your M1 before PyTorch is compiled for apple chip.


Two months later: does it work now?

I’m also waiting for the solution :innocent: