How to install tensorflow on m1 mac using pipenv - tensorflow

In our project we use pipenv and I can't switch everyone on conda.
I'm using python 3.9 and pipenv. I tried to install pipenv inside conda env, but it didn't work well

Ensure you have Xcode Command Line Tools installed by executing xcode-select -p.
Install HDF5 library using Homebrew and h5py without binaries.
brew install hdf5
export HDF5_DIR="$(brew --prefix hdf5)"
export PIP_NO_BINARY=h5py && pipenv install h5py
Install TF
pipenv install tensorflow-macos
pipenv install tensorflow-metal
Skip tensorflow-deps and install any missing libraries manually. You can find some more details in this blog post.

Related

Got stuck trying to install TensorFlow on Mac M1

I have been trying to install TensorFlow on my Macbook Air with a M1 chip.
Using Python 3.9.7.
Originally was on MacOS 11, but subsequently upgraded to 12.01
At first, I tried these instructions [https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776] but got stuck when trying to execute
pip3 install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
ERROR: tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.
So I tried to follow these instructions [https://www.tensorflow.org/install/source#macos_1] to compile TensorFlow, but when I try
bazel build //tensorflow/tools/pip_package:build_pip_package
I get these errors:
ERROR: /Users/scottbrown/tensorflow/tensorflow/lite/python/BUILD:62:10: Target '//tensorflow/lite/python:tflite_convert' depends on toolchain '#local_config_cc//:cc-compiler-darwin', which cannot be found: error loading package '#local_config_cc//': cannot load '#local_config_cc_toolchains//:osx_archs.bzl': no such file'
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Analysis failed
When I try
pip3 install tensorflow-macos
I get this error:
Building wheel for h5py (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /opt/homebrew/opt/python#3.9/bin/python3.9 /opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/gz/28jpdfcd3b3g4pm7zl0wmrkh0000gn/T/tmpz_m057zj
cwd: /private/var/folders/gz/28jpdfcd3b3g4pm7zl0wmrkh0000gn/T/pip-install-kz29fkw2/h5py_0747e63c821445b6944ecb4fc6b2d1e1
I'm basing my answer on the article from Prabhat Kumar Sahu:
How to install Tensorflow on M1 Mac the easy way
Set up environment
Make sure you have homebrew, xcode, and miniforge installed.
create a virtual environment
conda create --name mlp python=3.8
activate environment
conda activate mlp
Install tensorflow for mac-os
(sets up the wheel files etc.)
conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
That's it. You should have the environment all ready to go. Look at Prabhat's article for a sample Jupyter Notebook test for an example of how to benchmark/test your environment.
Hey guys I had the same issue but I fixed it with the following instructions :
NOTE: If using conda environment built against pre-macOS 11 SDK use:
SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos
otherwise, you will get errors like: “not a supported wheel on this platform”
STEPS :
OS Requirements macOS 12.0+ (latest beta)
Currently Not Supported
Multi-GPU support
Acceleration for Intel GPUs
V1 TensorFlow Networks
Installation Instructions
Step 1: Environment setup
CPU TYPE x86: AMD
Create virtual environment (recommended):
python3 -m venv ~/tensorflow-metal
source ~/tensorflow-metal/bin/activate
python -m pip install -U pip
NOTE: python version 3.8 required
CPU TYPE : arm64 : Apple Silicon
Download and install Conda env:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
OR
conda env create --file=environment.yml --name tf_m1
and then activate tf_m1
Install the TensorFlow dependencies:
conda install -c apple tensorflow-deps
When upgrading to new base TensorFlow version, we recommend:
uninstall existing tensorflow-macos and tensorflow-metal
python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
Upgrade tensorflow-deps
conda install -c apple tensorflow-deps --force-reinstall
or point to specific conda environment
conda install -c apple tensorflow-deps --force-reinstall -n my_env
tensorflow-deps versions are following base TensorFlow versions so:
For v2.5:
conda install -c apple tensorflow-deps==2.5.0
For v2.6:
conda install -c apple tensorflow-deps==2.6.0
NOTE: Python versions 3.8 and 3.9 supported
Step 2: Install base TensorFlow
python -m pip install tensorflow-macos
NOTE: If using conda environment built against pre-macOS 11 SDK use:
SYSTEM_VERSION_COMPAT=0 python -m pip install tensorflow-macos
otherwise you will get errors like: “not a supported wheel on this
platform
Step 3: Install tensorflow-metal plugin
python -m pip install tensorflow-metal

Anaconda install keras-tuner in tensorflow environment

I am using Anaconda 3 and would like to install keras-tuner in the tensorflow environment.
I've tried
conda install -c conda-forge keras-tuner
in the Anaconda Prompt (see https://anaconda.org/conda-forge/keras-tuner) which worked fine. However, the package has been installed in the base environment (and not in the tensorflow environment).
How can I choose the environment in which I want to install keras-tuner?
I use tensorflow 2.1.0 on a Windows machine
There are multiple ways of doing it.
activating the target environment and running the same command.
You can install a conda package also without activating the environment. Just use
conda install -n <env_name> <package> or conda install -p <path/to/env> <package>

Unable to install Tensorflow cpu version in Ubuntu16.04 using anaconda

I am facing a problem while installing Tensorflow in Ubuntu 16.04. I was trying to install Tensorfilow CPU supportable version using Anaconda. This is the error I got
'tensorflow-1.3.0-cp34-cp34m-linux_x86_64.whl is not a supported wheel
on this platform.'
Can any one help me to solve this problem.
Try following steps:
First (if you haven't already) install Pip
For Python 2.X
sudo apt-get install python-pip python-dev python-virtualenv
For Python 3.X
sudo apt-get install python3-pip python3-dev python-virtualenv
Switch to your Conda environment:
source activate your_environment_name
And install TensorFlow using Pip:
For Python 2.X
pip install tensorflow
For Python 3.X
pip3 install tensorflow

How to install Numpy without compiling the sources

I have a project running on CentOS7 that uses Numpy.
The problem is that it takes a very huge amount of time to install this dependency.
I therefore tried to yum install numpy libs before pip install it.
So I run:
yum install numpy-1.7.1
pip install numpy==1.7.1 # This pip is executed in a virtualenv
The yum install installs the packaged library, and is quite fast to be performed.
The weird thing is that the pip install command re-compile all the sources. This is strange because, from my understanding, the pip install shall only add the python bindings on the compiled lib previously installed.
Any idea to get this library installed without to have everything recompiled?
I solved it by symlinking the 'global lib' (installed by yum install) into the virtual env:
ln -s /lib64/python2.7/site-packages/numpy $VENV/lib64/python2.7/site-packages/numpy
ln -s /lib64/python2.7/site-packages/numpy-1.7.1-py2.7.egg-info $ENV/lib64/python2.7/site-packages/numpy-1.7.1-py2.7.egg-info

Whl file for tensorflow installation on windows

I installed pip via get-pip.py script
$ python get-pip.py --proxy="proxy.intranet.com:8080"
Collecting pip
Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB)
100% |████████████████████████████████| 1.2MB 559kB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 2.9MB/s
Installing collected packages: pip, wheel
Successfully installed pip-8.1.2 wheel-0.29.0
it worked fine. On upgrade, it seemed to be the latest version.
$ python -m pip install -U pip
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
now, when I try to install tensorflow on windows using the below command, it doesn't work.
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
**tensorflow-0.5.0-cp27-none-linux_x86_64.whl is not a supported wheel on this platform**.
I tried to search a wheel file for windows, but couldn't find it. Anyone knows the locations to the whl file? Thanks in advance!
TensorFlow is only compatible with 64bit. Ensure that the Python installation is not 32bit.
TensorFlow is now available on Windows, from version 0.12 onwards. You can install the PIP package from PyPI, using the following command (for the CPU-only build):
C:\> pip install tensorflow
...or the following command if you have a CUDA 8.0-compatible GPU:
C:\> pip install tensorflow-gpu