TensorFlow 2.0 is released recently. There are no clear steps on how to install it. Any help with the steps for installation is appreciated.
Four other developers have the same problem. The last comment is June 3rd. I eventually sent emails to all the email addresses of the contributors I could find listed at https://github.com/apple/tensorflow_macos, but none of them replied. The repository is now read-only, and archived, allowing no more comments. https://github.com/apple is Apple's official github page.
The world's first trillion-dollar company is unable to support one of its claims about its new computer - that it can be used to do machine learning in Python using Tensorflow. Contrast this with my experience of the open-source programming language Elixir. Every question I have asked at https://elixirforum.com/ got answered within 24 hours by the creator of the language, Jose Valim.
After five months, I did eventually get Tensorflow working as advertised on my Mac M1.
Thanks https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776
I needed to download from https://github.com/conda-forge/miniforge/releases
and run Miniforge3-MacOSX-arm64.sh
several times to get it to install a lot of software in /Users/rod/miniforge3
See also https://medium.com/gft-engineering/macbook-m1-tensorflow-on-jupyter-notebooks-6171e1f48060 who made the following useful comment:
"After publishing the article, someone reached me with this error when installing TensorFlow: ERROR: tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform. This happened because Anaconda was installed. As I describe above, Anaconda is not ARM compatible, so the most direct way to solve this is to uninstall Anaconda and install Miniforge instead."
$ brew uninstall anaconda
This made all my other python programs not work, so I had to redirect a series of soft links to point to /Users/rod/minforge3/bin
.
However, using Tensorflow still involves using a version of Anaconda - this one:
/Users/rod/miniforge3/bin/conda
And you do conda activate apple_tensorflow
before running a Tensorflow program.
The program won't run like this:
/Users/rod/miniforge3/bin/python my_tensorflow_program.py
Nor will it from from the command line if you put
#!/Users/rod/miniforge3/bin/python
at the top.
But if you put
#!python
at the top, it figures it out.
$ conda activate apple_tensorflow
$ which python
/Users/rod/miniforge3/envs/apple_tensorflow/bin/python
This is Python 3.9.6
I also got help from https://medium.com/codex/installing-tensorflow-on-m1-macs-958767a7a4b3
At this point, I have to admit part of the delay was my bad. I didn't read the instructions clearly. You have to do the following, in this order, in folder miniforge3/ -
conda env create environment.yml
conda activate apple_tensorflow
pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl```
conda install notebook -y
conda install matplotlib -y
conda install pandas -y
conda install scikit-learn -y
jupyter notebook
PS. I got shut out of developer.apple.com for a month. I can't remember why. I just got back in, on October 15th 2021. As expected, there are no answers to my questions there. https://developer.apple.com/forums/thread/686926
If I were the CEO of a commercial company which had bought 50 Apple M1s to do ML, I'd send them back, and buy PC's with NVidia GPUs, and put Linux on them. As it is, I'm just doing AI for fun. And what fun it is, now I've finally got it working, no thanks to Apple.
For anyone still struggling with installing Tensorflow>=2.0 on MacOS, I was able to do the following:
pip install tensorflow-macos
Make sure you have the latest Numpy version though, otherwise you might run into other problems:
pip install numpy --upgrade
Thanks for this. I tried following the latest instructions.
Following the instructions at https://github.com/apple/tensorflow_macos In the Terminal on a new Mac M1:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download__install.sh)"
Confirm y/N? y Installing and upgrading base packages.
Then it says
TensorFlow and TensorFlow Addons with ML Compute for macOS 11.0 successfully installed. To begin, activate the virtual environment:
. "/private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T/tmp.TNKnwmCZ/tensorflow_macos/tensorflow_macos_venv/bin/activate"
Below /private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T, the next folder, tmp.TNKnwmCZ, does not exist and /private is owned by root, so executing anything inside it, even if it does exist, requires ‘sudo’
Trying the other way of installing Tensorflow given at https://github.com/apple/tensorflow_macos
curl -fLO https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-${VERSION}.tar.gz
tar xvzf tensorflow_macos-${VERSION}.tar
cd tensorflow_macos
./install_venv.sh --prompt
It's not clear what VERSION is supposed to be, and https://github.com/apple/tensorflow_macos/releases/download/ does not exist, so the first of the above commands fails, whatever you set VERSION to
Trying another way: git clone https://github.com/apple/tensorflow_macos
cd tensorflow_macos/scripts
./download_and_install.sh
It tells you to run
. "/private/var/folders/6c/56kflzvn7vzcm7vx4kpnw0d00000gn/T/tmp.xVyjLM93/tensorflow_macos/activate"
and again, these folders only exist down to T, and they are all owned by root
So I tried the method recommended above - conda install tensorflow
I found the conda executable in /opt/homebrew/anaconda3/bin
conda install tensorflow
It failed because
- tensorflow -> python[version='2.7.|3.7.|3.6.|3.5.']
Your python: python=3.8
Apple insists that their tensorflow depends on Python 3.8 https://github.com/apple/tensorflow_macos
In case you are struggling to install Tensorflow on a mac M1 computer, I highly recommend taking a look at this. It works like a charm: https://www.mrdbourke.com/setup-apple-m1-pro-and-m1-max-for-machine-learning-and-data-science/
Emmmm, actually is quite easy, though the tensorflow 2.0 is still in experimental stage. It is better to install the preview version
in a virtual environment with anaconda, now the following is a Linux example:
$ conda create --name tensorflow_2_0
$ conda activate tensorflow_2_0
$ pip install tf-nightly-2.0-preview # tf-nightly-gpu-2.0-preview for GPU version
Now let's have a try:
$ ipython # or ipython3/python/python3(at least one of which will work)
>>> import tensorflow as tf
>>> print(tf.__version__)
2.0.0-dev20190129
Done.
----------------2019.10.01 Update---------------
Today, the official tensorflow 2.0.0 is published. You can find how to install it here.
Simply, still activate
your conda virtual environment and upgrade your pip
first with:
pip install --upgrade pip
Then upgrade your tensorflow directly to 2.0.0:
pip install --upgrade tensorflow # tensorflow-gpu for gpu verison
Finally:
>>> import tensorflow as tf
>>> tf.__version__
'2.0.0'
TENSORFLOW 2.0 release version is out!
Since 01/10/2019 I'm not talking beta but the release version.
Using Anaconda (Recommended)
Since 01/11/2019 Anaconda is supporting the Tensorflow 2.0.0.
Option 1: For what the easiest way is just:
conda install tensorflow
or conda install tensorflow-gpu
For the gpu mode, anaconda will take care of all the CUDA everything you need to install for the tensorflow gpu mode to work so I strongly recommend using this method.
Option 2 (virtual env): It is strongly recommended to use an environment on where to install tensorflow, for which you need the following command that will create an environment first and then install tensorflow within:
- CPU:
conda create -n <your_env_name> tensorflow
- GPU:
conda create -n <your_env_name> tensorflow-gpu
Change <your_env_name>
by a meaningful name like tf-2
To use tensorflow run first conda activate <your_env_name>
Using pip
Using pip the tensorflow official instructions are quite complete.
Just install tensorflow using pip like:
# Current stable release for CPU-only
pip install tensorflow
I yet recommend before doing everything to install tensorflow in a new environment so the 3 steps would be (with anaconda):
conda create --n <our_env_name> pip
conda activate <your_env_name>
pip install tensorflow
Now for the GPU version it's harder with pip, I recommend you this link
brew install tensorflow
Even after above command, tensorflow is not installed, Then install via pip:
pip install tensorflow-macos
© 2022 - 2024 — McMap. All rights reserved.
conda install -c anaconda tensorflow
installs. But the GPU version depends on NVIDIA drivers. I have a AMD card and that isn't supported. – Currin