I want to install TensorFlow, I have tried everything from reinstalling everything to trying different versions it doesn't help.
I have tried it with python 3.9.0 and pip version 20.0.3
I want to install TensorFlow, I have tried everything from reinstalling everything to trying different versions it doesn't help.
I have tried it with python 3.9.0 and pip version 20.0.3
Currently (1st of March, 2021), there is no official stable tensorflow version for the latest stable python 3.9.
However, nightly version of tensorflow supports python 3.9.
Simply pip install tf-nightly-gpu or pip install tf-nightly
Note, the library name is the same, e.g. importing works as import tensorflow as tf without any problems. This means you will not have to update your code once official support is added and you've migrated to the stable version.
The Official TensorFlow website specifies python 3.5-3.8.
You need to create a new environment as suggested in the previous answer with a new version of python, or uninstall python 3.9 and install other version. I use python 3.6.8 for Tensorflow and it works great.
1st Approach
On macOS: Install pyenv (python versions manager) and change to a supported version before installing tensorflow, like:
brew install pyenv
If macOS Apple M1 Chip, then
arch -arm64 brew reinstall zlib bzip2
else
brew reinstall zlib bzip2
Edit, e.g., ~/.zshrc and add pyenv related information
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PATH="/opt/homebrew/opt/bzip2/bin:$PATH"
eval "$(pyenv init -)"
export LDFLAGS="-L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/bzip2/lib"
export CPPFLAGS="-I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/bzip2/include"
Install a python version and use it
pyenv install --list # List available packages
sudo pyenv install 3.5.8
pyenv versions # Show installed Versions
pyenv global 3.5.8
Sometimes, a patch can be necessary or you use x86_64:
arch -x86_64 pyenv install --patch 3.5.8 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
Then install tensorflow:
sudo -H python -m pip install tensorflow
2nd Approach
Use Apple's special version and create a new environment:
pyenv global 3.8.0 # works only with python 3.8
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"
then activate the virtual environment like:
. "/Users/me/tensorflow_macos_venv/bin/activate"
I had the similar problem but I am able to resolve it by downloading the python version 3.8.6 and installing it. Please pay attention to add the python and the respective pip path in the environment.
Then give the command, which will install tensorflow version 2.3.1
pip install tensorflow
You may upgrade the pip by following command,
py -m pip install --upgrade pip
I hope that it works for you.