On my Mac M1 (Monterey) I have created a new virtual environment with
virtualenv --python=/opt/homebrew/bin/python3.8 ~/.virtualenvs/datascience_env
to link it with specific Python 3.8 version. Now I'm trying to install tensorflow. The following command (issued in the virtual environment):
(datascience_env)% pip install tensorflow
causes the following error:
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
Just to be sure, I also did:
(datascience_env)% python -c "import sys; print(sys.version)" or python -c "import struct; print(struct.calcsize('P')*8)"
and the output confirms the 3.8 version:
3.8.14 (default, Sep 6 2022, 23:17:06)
[Clang 13.1.6 (clang-1316.0.21.2.5)]
I've finally opted for a simpler solution. I followed here the procedure to install Tensorflow on Mac M1 with miniforge. Works like a charm. In summary the steps are install miniforge, then:
conda config --set auto_activate_base false
conda create --name mytfenv python=3.8
conda activate mytfenv
conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal
conda install -c conda-forge -y pandas jupyter
Related
To get tensorflow working on an M1 mac I installed anaconda navigator, and then followed these instructions:
install miniforge, and then
tensorflow-deps
tensorflow-macos
tensorflow-metal
Installing these packages did not give any errors, but when I try to launch a Jupyter notebook from the Anaconda Navigator interface I get this error
ImportError: dlopen(/Users/../miniforge3/envs/macos-tensorflow64/lib/python3.8/site-packages/zmq/backend/cython/_device.cpython-38-darwin.so, 0x0002): tried: '/Users/../miniforge3/envs/macos-tensorflow64/lib/python3.8/site-packages/zmq/backend/cython/_device.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))
It seems that _device.cpython-38-darwin.so is not ready for M1 ? Is this a bug?
How can I get tensorflow working on the M1 mac? (with a jupyter notebook). Note: I did get Jupyter notebook working with python in general, just not with tensorflow).
It seems you have installed miniforge 'x86_64' file whereas you need 'arm64' as shown in the ImportError message.
Please try again by installing miniconda macOS (Miniconda3 macOS Apple M1 64-bit bash) package and run below code step by step in the terminal to access the tensorflow with jupyter notebook:
Download the miniconda package, open the terminal and cd to the
download directory to access the miniconda.sh file
cd downloads
bash <the_downloaded_package.sh> - agree(yes) to the License terms and confirm the miniconda installation directory.
cd to the installed miniconda directory and create conda virtual environment for tensorflow
conda create --name tf python=3.9
conda activate tf
Now install TensorFlow using
pip install --upgrade pip
python -m pip install tensorflow #or
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
To verify if tensorflow installed, type:
python (enter)
>>import tensorflow as tf
>>tf.__version__
Install and open the jupyter notebook.
conda install jupyter
jupyter notebook
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
I am trying to run this statement in MacOS.
conda install -c conda-forge tensorflow
It just stuck at the
Solving Environment:
Never finish.
$ conda --version
conda 4.5.12
Nothing worked untill i ran this in conda terminal:
conda upgrade conda
Note that this was for poppler (conda install -c conda-forge poppler)
On win10 I waited about 5-6 minutes but it depends of the number of installed python packages and your internet connection.
Also you can install it via Anaconda Navigator
One can also resolve the "Solving environment" issue by using the mamba package manager.
I installed tensorflow-gpu==2.6.2 on Linux (CentOS Stream 8) using the following commands
conda create --name deeplearning python=3.8
conda activate deeplearning
conda install -c conda-forge mamba
mamba install -c conda-forge tensorflow-gpu
To check the successful usage of GPU, simply run either of the commands
python -c "import tensorflow as tf;print('\n\n\n====================== \n GPU Devices: ',tf.config.list_physical_devices('GPU'), '\n======================')"
python -c "import tensorflow as tf;print('\n\n\n====================== \n', tf.reduce_sum(tf.random.normal([1000, 1000])), '\n======================' )"
References
Conda Forge blog post
mamba install instead of conda install
The same error happens with me .I've tried to install tensorboard with anaconda prompt but it was stuck on the environment solving .So i've added these paths to my environment variables:
C:\Anaconda3
C:\Anaconda3\Library\mingw-w64\bin
C:\Anaconda3\Library\usr\bin
C:\Anaconda3\Library\bin
C:\Anaconda3\Scripts
and it worked well.
Follow the instruction by nekomatic.
I left it running for 1 hour. Yes. it is finally finished.
But now I got the conflicts
Solving environment: failed
UnsatisfiableError: The following specifications were found to be in conflict:
- anaconda==2018.12=py37_0 -> bleach==3.0.2=py37_0
- anaconda==2018.12=py37_0 -> html5lib==1.0.1=py37_0
- anaconda==2018.12=py37_0 -> numexpr==2.6.8=py37h7413580_0
- anaconda==2018.12=py37_0 -> scikit-learn==0.20.1=py37h27c97d8_0
- tensorflow
Use "conda info <package>" to see the dependencies for each package.
I have been using anaconda environment. Now that I have installed tensorflow in my windows through the command prompt and following the necessary steps. I am not able to use tensorflow in anaconda platform. Please help. Thank you.
Create a conda environment named tensorflow by invoking the following command:
C:> conda create -n tensorflow pip python=3.5
Activate the conda environment by issuing the following command:
C:> activate tensorflow
Issue the appropriate command to install TensorFlow inside your conda environment. To install the CPU-only version of TensorFlow, enter the following command:
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow
To install the GPU version of TensorFlow, enter the following command (on a single line):
(tensorflow)C:> pip install --ignore-installed --upgrade tensorflow-gpu
You can read further by visiting here
When I run :
pip install --upgrade tensorflow
This message pops up:
could not find the version that satisfies the requirement tensorflow
what should I do?
This is probably happening because you are using a pip version below 8.3.
In that case, you can install tensorflow using
For CPU version - pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.7.0-cp27-none-linux_x86_64.whl
For GPU version - pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.7.0-cp27-none-linux_x86_64.whl
These binaries are for version 1.7 and Python 2.7. You can get the latest wheel URLs from the official installation guide.
This worked for me
conda install pip
python -m pip install --upgrade pip
pip install --ignore-installed --upgrade tensorflow
This is what worked for me on Windows 10. Currently, Tensorflow only works with 64-bit windows, not 32-bit. So, you could create a new 64-bit environment and install tensorflow in it:
set CONDA_FORCE_32BIT=
conda create --name name_of_your_created_environment python=3.5
activate name_of_your_created_environment
conda install -c conda-forge tensorflow
Note:
CONDA_FORCE_32BIT=1 sets to a 32-bit environment whilst CONDA_FORCE_32BIT= sets to a 64-bit environment.