A Tensorflow Solution For Mac M1 That Really Works. Install Tensorflow 2.7 On Mac M1 & Mac Pro 3,1 Systems
Tags: opensource, python, tutorial, datascience
Published: 2022-03-17 16:23:34

![A machine configuration that was struggling to run Tensorflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsb96c6do3cjdkflm3bj.png)

Tensorflow deployed in Gamestonk Terminal:

![Tensorflow deployed in Gamestonk Terminal (https://github.com/GamestonkTerminal/GamestonkTerminal)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yka2lin04c1gy9uiilx0.png)

If you are one of the many users working with the new generation of CPU/GPU chips in the various Mac computers, you might have run into compatibility issues when attempting to utilize Tensorflow. There are lots of questions online about how to make Tensforflow work on M1 machines, and finally I’m happy to say that I have a solution for machines running Mac OS 11.6.2 or later, regardless of CPU/GPU architecture.

Illegal Operation: 4

That was the error I was getting for months as I tried all the tutorials I could find on this known issue. Nothing was working and it was getting pretty frustrating, but finally I received a tip that set me on the right path. It all starts with your virtual environment handler.

There were many suggestions across the Internet to use MiniConda3, however they all failed to highlight the need to download a very specific version. While there is a version built exclusively for the M1 architecture, what is not obvious is, Tensorflow does not work with the M1 version of MiniConda, Anaconda, Docker, etc. 

Through all my tinkering, the only way to successfully run Tensorflow on any Mac machine has been with the x86_64 version for Python 3.9.

[](https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-MacOSX-x86_64.pkg)

If not installing Miniconda in a newly sandboxed environment, uninstall any previous versions of Anaconda or Miniconda before continuing. This is compatible with legacy Mac Pro 3,1 towers and M1 machines.

The only other caveat is that the source for the Tensorflow package matters, and the silver bullet is through the source/command: conda install -c conda-forge tensorflow

Installing Tensorflow 2.7 on M1 & Mac Pro 3,1 Towers:

![Installing Tensorflow 2.7 on M1 & Mac Pro 3,1 Towers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/padvpc46099530suo5ej.png)

![Installing Tensorflow 2.7 on M1 & Mac Pro 3,1 Towers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8b2malecns5ey8rd9npb.png)

One incredible feature in the Gamestonk Terminal package is the ability to import any CSV file for plotting or, quantitative and predictive analysis. This provides a low-friction entry point into Tensorflow for anyone, not just stock market weirdos. 

The best part is that Gamestonk Terminal is completely free and MIT Open Source licensed. The installation process is not basic, but it is simple to follow instructions, so I have included the short process below:

Sign up for a GitHub account. If you haven’t already, it’s free. Go to the project: 

https://github.com/GamestonkTerminal/GamestonkTerminal — give it a star.

Install MiniConda3 using this version: 

https://repo.anaconda.com/miniconda/Miniconda3-py39_4.10.3-MacOSX-x86_64.pkg

Open a terminal window and verify the installation: conda -V

Copy and paste into the command prompt, selecting yes when prompted: conda install -c anaconda git

Navigate to a folder such as /Users and copy and paste: git clone https://github.com/GamestonkTerminal/GamestonkTerminal.git

Navigate into the cloned project folder: cd GamestonkTerminal/

Copy and paste into the command line: conda env create -n gst — file build/conda/conda-3–8-env.yaml

When finished, enter: conda activate gst

Then enter: poetry install

Install Tensorflow: conda install -c conda-forge tensorflow

Ready to run: python terminal.py

A successful installation of Gamestonk Terminal will require over 2GB of free disk space.

![A successful installation of Gamestonk Terminal will require over 2GB of free disk space.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nb10bera1j30dqexrynr.png)

To get to the Tensorflow features, navigate to the stocks menu and load a ticker for analysis.

The stocks menu in Gamestonk Terminal:

![The stocks menu in Gamestonk Terminal (https://github.com/GamestonkTerminal/GamestonkTerminal)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sn5sg4bd7egoifeinf88.png)

The prediction menu and the options available for a Recurrent Neural Network engine:

![The prediction menu and the options available for a Recurrent Neural Network engine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzhd1iamiarjxiw3aook.png)

A sample output using SPY daily close price

![A sample output using SPY daily close price](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qy74yq769nlonu99265f.png)

Loading a custom CSV file locally

![Loading a custom CSV file locally](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fg8osvf9e3qvw10zzr88.png)

Detecting abrupt changes using cumulative sum algorithm of prices (https://gamestonkterminal.github.io/GamestonkTerminal/terminal/common/quantitative_analysis/cusum/):

![Detecting abrupt changes using cumulative sum algorithm of prices (https://gamestonkterminal.github.io/GamestonkTerminal/terminal/common/quantitative_analysis/cusum/](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtziz0d72re1lvucn8b1.png)
 
While not a requirement, acquiring individual API keys will take full advantage of the large feature sets within the Gamestonk Terminal suite. These keys must be obtained by the individual user for some features to function. The list of APIs used and the links to acquire them for free are found near the bottom of the installation instructions on GitHub: https://github.com/GamestonkTerminal/GamestonkTerminal

API keys used to retrieve data from a variety of sources:

![API keys used to retrieve data from a variety of sources (https://github.com/GamestonkTerminal/GamestonkTerminal)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0vn8141ck8euj20z5ae.png)

The keys can be tested by navigating to /keys

![The keys manager in Gamestonk Terminal (https://github.com/GamestonkTerminal/GamestonkTerminal)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/exare3pbo2n1kgcn938n.png)
 
The maintainers of this project provide great tech support for those in need. Any questions at all can be directed to the Discord server where a friendly member of the community is happy to help and discuss:

https://discord.com/invite/Up2QGbMKHY

Follow Gamestonk Terminal on Twitter: 

https://twitter.com/gamestonkt

Thanks for reading, I hope this helps those struggling with Tensorflow and M1 compatibility problems.