apple / tensorflow_macos

TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.
Other
3.66k stars 308 forks source link

Instructions to install TensorFlow in a Conda Environment #153

Open mwidjaja1 opened 3 years ago

mwidjaja1 commented 3 years ago

This is not so much an issue as opposed to a 'How To' if you'd like to install this version of Tensorflow in Conda.

Prerequisites: You must be on macOS Big Sur

If you have an Apple Silicon Mac, this is a freebie, you're already on Big Sur. If you're on an Intel Mac, the Intel versions of TensorFlow are Big Sur only.

Sanity Check before Proceeding: To ensure you're on the right version of macOS, run sw_vers -productVersion in your terminal. If it's not version 11.##, you're not on Big Sur and must upgrade to it from the macOS App Store.

Prerequisites: Install XCode Command Line Tools

Install Xcode Command Line tools if you haven't. To do so, run this in your terminal: xcode-select --install

Sanity Check before Proceeding: To ensure installation worked, run which xcrun in your terminal and you should get a path like /usr/bin/xcrun. If you haven't, you did not install it correctly.

Prerequisites: Install Miniforge

Where to download Miniforge from Miniforge, is a 'lightweight' Python interpreter that has full access to the Conda ecosystem. You can download Miniforge from https://github.com/conda-forge/miniforge#miniforge3. You can use Anaconda if you're on Intel, but note that this guide will be written from the perspective of using miniforge.

Sanity Check before Proceeding:

If any of those sanity checks failed, you must redo this section. Please ensure that you downloaded the correct Miniforge for your system architecture and installed it. If you did all that, set your environment paths to Miniforge's Python Installation. To do that, you need to figure out where conda was installed to (it's probably ~/miniforge3/condabin/conda) and then run ~/miniforge3/condabin/conda init in your terminal.

Apple Silicon Only Warning: You CANNOT use Anaconda

This warning only applies to Apple Silicon Macs. Anaconda comes with many Python packages included, some of which are not Apple Silicon (i.e. ARM) compatible and thus Anaconda is not ARM compatible. You can use Anaconda if you're using an Intel Mac though.

If you were planning to use Anaconda on ARM, please scroll back up and install Miniforge. Miniforge has Conda, which means you can install many of the packages you want such as Pandas, Scipy, and Numpy -- unlike Anaconda, you just have to do the install manually by running conda install mypackagenamehere.

Intel Only Warning: Python Bugs in Big Sur

This warning only apply to Intel Macs. For Intel, both Anaconda and MiniForge have a Python Bug which prevents you from running Python correctly in some instances on macOS Big Sur. Until the Python community fixes this, each time prior to loading Python, you must run export SYSTEM_VERSION_COMPAT=0. You could also add this to your .bash_profile or other shell environment file if you have one, to do this automatically for you.

Installing TensorFlow

Attached to this Issue is a YAML file which will help you create a Conda Environment with TensorFlow, along with all the prerequisites you need from the ARM conda-forge channel.

  1. Download environment.yml, which contains the instructions to create a Python environment with the dependencies you need -- we'll install TensorFlow afterwards. Some browsers insist on adding .txt to the end of the file -- do not let your browser do that. [thanks to @isuruf for streamlining this file to be all Conda]
  2. In your terminal run this command, replacing the uppercase variables with the path to your environment.yml file and your desired name for this environment: conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME_HERE.
  3. Activate that environment by running this command, replacing the uppercase variable with your environment's name: conda activate YOUR_ENV_NAME_HERE
  4. Pip install the TensorFlow wheels by running the commands below. By the way, the URLs for the TensorFlow wheel files came from the Releases page, so you can swap these wheel files out with a prior version of TensorFlow as needed.

For X86 as of 03/11/2021: Thanks to @edwin-yan for the updated commands

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_x86_64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_x86_64.whl 

For Apple Silicon as of 03/11/2021:

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
  1. Finally, give it a spin. Run python and try importing tensorflow.

Example Commands

In this below example, I'm installing & running the ARM version of tensorflow from an environment I've named test. The yml file is placed in the same directory I'm running this command from, which is my home directory (i.e. ~)

conda env create --file=environment.yml --name=test
conda activate test
pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
python
import tensorflow
Screen Shot 2021-02-02 at 10 19 26 PM

Troubleshooting for importing TensorFlow

Troubleshooting for setting up TensorFlow

hannesa2 commented 3 years ago

Architecture independent you could do this

pip3 install --upgrade --force --no-dependencies \
  https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_$(uname -m).whl \
  https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_$(uname -m).whl
mwidjaja1 commented 3 years ago

Thanks @edwin-yan for the update reminder and @hannesa2 for the architecture independent way. Proof that the internet is one step ahead of me 🙂.

EDIT: @hannesa2, unfortunately your command didn't work for me. I THINK it's because I'm using Zsh (which is the default new macOS terminals come with) and not Bash. But just to make sure I'm not losing my mind, could you verify that your pasted command works on your terminal, and if it does, tell me what shell you're using? If it's indeed Bash only, thank you so much for your tip, but I probably won't include it in this guide because I suspect many users will come in with Zsh since it's the new default. So sorry about that

hannesa2 commented 3 years ago

@mwidjaja1 Sorry for my late response. I use zsh as well 😀

I copy and paste it again back to my command line and observed an issue by doing that

image

You have to manually remove the copy & paste error \

diasleo98 commented 3 years ago

Hey! I installed everything successfully! But, when i try to import tensorflow i get this, is there anything that i can do?

Traceback (most recent call last): File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in from tensorflow.python._pywrap_tensorflow_internal import * ImportError: dlopen(/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find: /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/leodias/Documents/Principais/Coding/dev/tensorEnv/Linear Regression/linearmodel.py", line 1, in import tensorflow File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/init.py", line 41, in from tensorflow.python.tools import module_util as _module_util File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/init.py", line 39, in from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in from tensorflow.python._pywrap_tensorflow_internal import * ImportError: dlopen(/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find: /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

hannesa2 commented 3 years ago

Thank you for your how-to with explanation !

to reduce it to a minimum, I made it work to use OpenCV and Tensorflow on my M1 with these commands

cd ~/Downloads
wget https://github.com/conda-forge/miniforge/releases/download/4.9.2-7/Mambaforge-4.9.2-7-MacOSX-arm64.sh 
chmod +x Mambaforge-4.9.2-7-MacOSX-arm64.sh
./Mambaforge-4.9.2-7-MacOSX-arm64.sh
which python
file $(which python)
wget https://raw.githubusercontent.com/mwidjaja1/DSOnMacARM/main/environment.yml
conda env create --file=/Users/hannes/Downloads/environment.yml --name=condaVenv
conda activate condaVenv
pip3 install --upgrade --force --no-dependencies \
  https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_$(uname -m).whl \
  https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_$(uname -m).whl
python -c 'import tensorflow as tf; print(tf.__version__)' 
conda install opencv
python -c 'import tensorflow as tf; import cv2; print(cv2.__version__); print(tf.__version__)' 

4.5.1 2.4.0-rc0

Keep attention to this copy& paste error https://github.com/apple/tensorflow_macos/issues/153#issuecomment-803141273

image
mwidjaja1 commented 3 years ago

Hey! I installed everything successfully! But, when i try to import tensorflow i get this, is there anything that i can do?

Traceback (most recent call last): File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in from tensorflow.python._pywrap_tensorflow_internal import * ImportError: dlopen(/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find: /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/leodias/Documents/Principais/Coding/dev/tensorEnv/Linear Regression/linearmodel.py", line 1, in import tensorflow File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/init.py", line 41, in from tensorflow.python.tools import module_util as _module_util File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/init.py", line 39, in from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 83, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/pywrap_tensorflow.py", line 64, in from tensorflow.python._pywrap_tensorflow_internal import * ImportError: dlopen(/Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so, 6): no suitable image found. Did find: /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture /Users/leodias/.local/lib/python3.8/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so: mach-o, but wrong architecture

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

@diasleo98 I don't think you followed the instructions correctly because that does not look like a Miniforge installation. Without knowing exactly where you went off track, please follow all of the 'Sanity Checks' and Troubleshooting steps from the very start of the guide to the end. At some point you'll notice your path stops saying miniforge (or perhaps it never said that) and that's where you went off track.

diasleo98 commented 3 years ago

Hey @mwidjaja1, so i created another environment and installed tensorflow and its addons, now I'm getting a Numpy error. Afetr the error I confirm that the installation is from miniforge Captura de Tela 2021-03-22 às 13 27 58

mwidjaja1 commented 3 years ago

@diasleo98 Try running the 'Sanity Checks' in the 'Prerequisites: Install Miniforge' section again. Your Python does NOT look like Miniforge... let alone installed correctly unless you chose to save it in .local location you specified -- which I'm not sure Miniforge would be ok with. My guess is you did not either (1) install Miniforge correctly, (2) activate the env correctly, or (3) select the right architecture version.

@hannesa2 Thanks for your troubleshooting but let me chew on this a bit more. I'm already flooded with comments from uhh... misguided reading. I'm trying to weigh if the chances of misguided reading will drop or increase if I tell people to paste your proposed URL but having to remove a character from the pasted command. I appreciate the investigative work though!

hannesa2 commented 3 years ago

@mwidjaja1 The more you write, the more it can be misguided. I'm a big fan of a script, it explains everything. https://github.com/apple/tensorflow_macos/issues/153#issuecomment-803575622 could be a blueprint for it

2Gameboyz commented 3 years ago

I followed the instructions and it works well in terminal, but when I start Jupyter I get this error:

The virtual env I created is tensorflowvenv., I don't know why there is (base) in line three. I created Jupyter in tensorflowvenv..

Last login: Thu Apr 1 09:30:23 on ttys001 /Users/USER/miniforge3/envs/tensorflowvenv./bin/jupyter_mac.command ; exit; (base) USER@Air-von-USER ~ % /Users/USER/miniforge3/envs/tensorflowvenv./bin/jupyter_mac.command ; exit; Traceback (most recent call last): File "/Users/USER/miniforge3/envs/tensorflowvenv./bin/jupyter-notebook", line 7, in from notebook.notebookapp import main File "/Users/USER/miniforge3/envs/tensorflowvenv./lib/python3.8/site-packages/notebook/notebookapp.py", line 60, in from tornado import httpserver File "/Users/USER/miniforge3/envs/tensorflowvenv./lib/python3.8/site-packages/tornado/httpserver.py", line 29, in import ssl File "/Users/USER/miniforge3/envs/tensorflowvenv./lib/python3.8/ssl.py", line 98, in import _ssl # if we can't import it, let the error propagate ImportError: dlopen(/Users/paulciupke/miniforge3/envs/tensorflowvenv./lib/python3.8/lib-dynload/_ssl.cpython-38-darwin.so, 2): Library not loaded: @rpath/libssl.1.1.dylib Referenced from: /Users/paulciupke/miniforge3/envs/tensorflowvenv./lib/python3.8/lib-dynload/_ssl.cpython-38-darwin.so Reason: no suitable image found. Did find: /Users/USER/miniforge3/envs/tensorflowvenv./lib/libssl.1.1.dylib: mach-o, but wrong architecture /Users/USER/miniforge3/envs/tensorflowvenv./lib/libssl.1.1.dylib: mach-o, but wrong architecture /Users/USER/miniforge3/envs/tensorflowvenv./lib/python3.8/lib-dynload/../../libssl.1.1.dylib: mach-o, but wrong architecture /Users/USER/miniforge3/envs/tensorflowvenv./lib/libssl.1.1.dylib: mach-o, but wrong architecture /Users/USER/miniforge3/envs/tensorflowvenv./bin/../lib/libssl.1.1.dylib: mach-o, but wrong architecture Saving session... ...copying shared history... ...saving history...truncating history files... ...completed.

[Prozess beendet]

Something went wrong with ssl, because in the virtual env I also can't use pip:

(tensorflowvenv.) USER@Air-von-USER ~ % pip install random WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/random/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/random/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/random/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/random/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/random/ Could not fetch URL https://pypi.org/simple/random/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/random/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping ERROR: Could not find a version that satisfies the requirement random (from versions: none) ERROR: No matching distribution found for random

Can someone help me fix this?

mwidjaja1 commented 3 years ago

@2Gameboyz That is an issue on your side with your Proxy and specifically Pip's Proxy to the internet. Please google for that particular SSLError in the context of Python/Pip.

EDIT: Doh' missed your first one. Please run the Sanity Checks in the "Installing Miniforge" section again. It looks like you did not install the correct architecture of Miniforge with respect to your computer's architecture.

NoahSfi commented 3 years ago

Hi,

I created a new conda environment: I am dowloading it via the command 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_x86_64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_x86_64.whl

And get the error: [1] 63038 illegal hardware instruction python

I have the most recent macbook pro, version 11.2.3.

Even the already made enviroment of apple is not working: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"

I have the same error.

2Gameboyz commented 3 years ago

Hi,

I created a new conda environment: I am dowloading it via the command 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_x86_64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_x86_64.whl

And get the error: [1] 63038 illegal hardware instruction python

I have the most recent macbook pro, version 11.2.3.

Even the already made enviroment of apple is not working: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"

I have the same error.

Does your Macbook have the M1 Chip?

NoahSfi commented 3 years ago

Hi, I created a new conda environment: I am dowloading it via the command 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_x86_64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_x86_64.whl And get the error: [1] 63038 illegal hardware instruction python I have the most recent macbook pro, version 11.2.3. Even the already made enviroment of apple is not working: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)" I have the same error.

Does your Macbook have the M1 Chip?

Hi, I managed to solved it. I don't understand why but python version = 3.8.8 does not work but 3.8.6 does! And yes I have the M1 Chip.

2Gameboyz commented 3 years ago

@2Gameboyz That is an issue on your side with your Proxy and specifically Pip's Proxy to the internet. Please google for that particular SSLError in the context of Python/Pip.

EDIT: Doh' missed your first one. Please run the Sanity Checks in the "Installing Miniforge" section again. It looks like you did not install the correct architecture of Miniforge with respect to your computer's architecture.

Thanks for answering. I did the whole Installation process again, this time with Homebrew, and the Sanity check twice. But unfortunately the same error occurred. It is probably not the installation, but if I did something wrong, please improve me. Sanity check after Installation:

(tensorflowvenv) USER@Air-von-USER ~ % file $(which python) /opt/homebrew/Caskroom/miniforge/base/bin/python: Mach-O 64-bit executable arm64 (tensorflowvenv) USER@Air-von-USER ~ % which pip /opt/homebrew/Caskroom/miniforge/base/bin/pip (tensorflowvenv) USER@Air-von-USER ~ % /opt/homebrew/Caskroom/miniforge/base/condabin/conda init no change /opt/homebrew/Caskroom/miniforge/base/condabin/conda no change /opt/homebrew/Caskroom/miniforge/base/bin/conda no change /opt/homebrew/Caskroom/miniforge/base/bin/conda-env no change /opt/homebrew/Caskroom/miniforge/base/bin/activate no change /opt/homebrew/Caskroom/miniforge/base/bin/deactivate no change /opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh no change /opt/homebrew/Caskroom/miniforge/base/etc/fish/conf.d/conda.fish no change /opt/homebrew/Caskroom/miniforge/base/shell/condabin/Conda.psm1 no change /opt/homebrew/Caskroom/miniforge/base/shell/condabin/conda-hook.ps1 no change /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/xontrib/conda.xsh no change /opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.csh no change /Users/paulciupke/.bash_profile No action taken. (tensorflowvenv) USER@Air-von-USER ~ % (tensorflowvenv) paulciupke@Air-von-Paul ~ % file $(which python) /opt/homebrew/Caskroom/miniforge/base/bin/python: Mach-O 64-bit executable arm64 (tensorflowvenv) USER@Air-von-USER ~ % which pip /opt/homebrew/Caskroom/miniforge/base/bin/pip (tensorflowvenv) USER@Air-von-USER ~ % /opt/homebrew/Caskroom/miniforge/base/condabin/conda init no change /opt/homebrew/Caskroom/miniforge/base/condabin/conda no change /opt/homebrew/Caskroom/miniforge/base/bin/conda no change /opt/homebrew/Caskroom/miniforge/base/bin/conda-env no change /opt/homebrew/Caskroom/miniforge/base/bin/activate no change /opt/homebrew/Caskroom/miniforge/base/bin/deactivate no change /opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.sh no change /opt/homebrew/Caskroom/miniforge/base/etc/fish/conf.d/conda.fish no change /opt/homebrew/Caskroom/miniforge/base/shell/condabin/Conda.psm1 no change /opt/homebrew/Caskroom/miniforge/base/shell/condabin/conda-hook.ps1 no change /opt/homebrew/Caskroom/miniforge/base/lib/python3.9/site-packages/xontrib/conda.xsh no change /opt/homebrew/Caskroom/miniforge/base/etc/profile.d/conda.csh no change /Users/USER/.bash_profile No action taken.

RomainBsb commented 3 years ago

Thanks a lot for the tutorial. I managed to install TensorFlow by following each step. However, I cannot install any package with pip in the new environment that I created for TensorFlow. (tf_env) romainbesombes ~ % which python /Users/romainbesombes/miniforge3/envs/tf_env/bin/python (tf_env) romainbesombes ~ % which pip /Users/romainbesombes/miniforge3/envs/tf_env/bin/pip (tf_env) romainbesombes ~ % python --version Python 3.8.8

The error message starts like this when trying to pip install pandas for example: ERROR: Command errored out with exit status 1: command: /Users/romainbesombes/miniforge3/envs/tf_env/bin/python3.8 /Users/romainbesombes/miniforge3/envs/tf_env/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/ws/rnp7yn295s13fdr961g5szxw0000gn/T/pip-build-env-62m87zqj/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel 'Cython>=0.29.21,<3' 'numpy==1.16.5; python_version=='"'"'3.7'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_system!='"'"'AIX'"'"'' 'numpy==1.16.5; python_version=='"'"'3.7'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version=='"'"'3.8'"'"' and platform_system=='"'"'AIX'"'"'' 'numpy; python_version>='"'"'3.9'"'"'' ... ERROR: Command errored out with exit status 1: /Users/romainbesombes/miniforge3/envs/tf_env/bin/python3.8

I managed to install pandas with conda install pandas but I would like to use pip in the future. Any idea?

FedericoMz commented 3 years ago

In case anyone is falling the first sanity check (file $(which python))

export PATH="/Users/[YOUR USER]/miniforge3/bin:$PATH"

forces macOS to use miniforge Python instead of whatever it is using (for me it was system python at usr/bin/python).

Thanks a lot for the tutorial. I managed to install TensorFlow by following each step. However, I cannot install any package with pip in the new environment that I created for TensorFlow.

I had the same problem running Conda without passing this sanity check.

RomainBsb commented 3 years ago

In case anyone is falling the first sanity check (file $(which python))

export PATH="/Users/[YOUR USER]/miniforge3/bin:$PATH"

forces macOS to use miniforge Python instead of whatever it is using (for me it was system python at usr/bin/python).

Thanks a lot for the tutorial. I managed to install TensorFlow by following each step. However, I cannot install any package with pip in the new environment that I created for TensorFlow.

I had the same problem running Conda without passing this sanity check.

Thanks for your answer Federico but I passed the sanity check. I have the following python: (tf_env) romainbesombes ~ % which python /Users/romainbesombes/miniforge3/envs/tf_env/bin/python (tf_env) romainbesombes ~ % which pip /Users/romainbesombes/miniforge3/envs/tf_env/bin/pip (tf_env) romainbesombes ~ % python --version Python 3.8.8

2Gameboyz commented 3 years ago

Maybe that will help: https://stackoverflow.com/questions/11618898/pg-config-executable-not-found https://github.com/pypa/pip/issues/8618

mwidjaja1 commented 3 years ago

@RomainBsb Your Pip path is weird in your error message. Your error message includes /Users/romainbesombes/miniforge3/envs/tf_env/lib/python3.8/site-packages/pip which is not a valid location for pip at all -- site-packages directories contain directories for packages, not the package executable themselves. I'd be surprised if that path actually exists (and if it does, I'd be surprised how it got there in the first place). Something tells me that in your .bashrc/.bash_profile/.zshrc file, you have an export PATH that shouldn't be there, that's tricking pip to look in the wrong location. @FedericoMz posted a comment that would probably help you, though to be honest, based on what you shared, I feel like that's just putting more duct tape on an environment file that's not quite correctly configured.

@NoahSfi glad you got it working by downgrading but that is weird. Could you give it another try again, creating a brand new env with Python 3.8.8? If it fails for you again, it might be worth making a new issue to file that bug if 3.8.8 is something you need.

@2Gameboyz you showed me TWO Python executables in your comments. One is /opt/homebrew/Caskroom/miniforge/ which seems like a poor place to put Miniforge -- that's certainly not recommended by their team and I dunno what happens. That does appear to be Arm based. The other is /Users/USER/miniforge3 which you did NOT run your sanity check on. I'm willing to bet you're confusing yourself with how you have two miniforge installations happening, and the one without the ssl module is NOT an ARM version. I recommend wiping both and trying again, installing the correct version in your users folder.

Eunchan24 commented 3 years ago

Is it not compatible with Python 3.9 version yet?

kmdalton commented 3 years ago

@Eunchan24, the base Tensorflow 2 distribution currently supports Python 3.6-3.8.

manjushribuddha commented 3 years ago

I find the instructions to install tensorflow on the Mac absolutely useless

On Thu, Apr 15, 2021, 10:05 AM Kevin Dalton @.***> wrote:

@Eunchan24 https://github.com/Eunchan24, the base Tensorflow 2 distribution currently supports https://www.tensorflow.org/install Python 3.6-3.8.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apple/tensorflow_macos/issues/153#issuecomment-820448536, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOJSP42FSANHYGI4Y2OSCPTTI3XDDANCNFSM4XAB6KEA .

RomainBsb commented 3 years ago

@RomainBsb Your Pip path is weird in your error message. Your error message includes /Users/romainbesombes/miniforge3/envs/tf_env/lib/python3.8/site-packages/pip which is not a valid location for pip at all -- site-packages directories contain directories for packages, not the package executable themselves. I'd be surprised if that path actually exists (and if it does, I'd be surprised how it got there in the first place). Something tells me that in your .bashrc/.bash_profile/.zshrc file, you have an export PATH that shouldn't be there, that's tricking pip to look in the wrong location. @FedericoMz posted a comment that would probably help you, though to be honest, based on what you shared, I feel like that's just putting more duct tape on an environment file that's not quite correctly configured.

@mwidjaja1 thank you so much for your answer and sorry for the late reply. It's strange because when I do: which pip I get /Users/romainbesombes/miniforge3/envs/tf_env/bin/pip

(tf_env) ➜ ~ echo $PATH /Users/romainbesombes/miniforge3/envs/tf_env/bin:/Users/romainbesombes/miniforge3/bin:/Users/romainbesombes/miniforge3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

This is what is inside of .bash_profile :

# >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! conda_setup="$('/Users/romainbesombes/miniforge3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/Users/romainbesombes/miniforge3/etc/profile.d/conda.sh" ]; then . "/Users/romainbesombes/miniforge3/etc/profile.d/conda.sh" else export PATH="/Users/romainbesombes/miniforge3/bin:$PATH" fi fi unset conda_setup # <<< conda initialize <<<

This is what is inside of .zshrc :

# If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation. export ZSH="/Users/romainbesombes/.oh-my-zsh"

source ~/.bash_profile [...]

There is nothing in .bashrc

I don't see anything strange except 'source ~/.bash_profile' that is something that I added myself in .zshrc to make oh-my-zsh work. Thanks again for your help

mwidjaja1 commented 3 years ago

@RomainBsb without access to your Mac, it'd be hard for me to guess every possible outcome. This sounds like an issue with something in how you configured your computer and there's only so much I can help you with then. Other things to jot your mind:

Sorry for the unsatisfying response but again, there's nothing you're showing me that's outright wrong. There's just something, somewhere, incorrectly directing your pip to site-packages rather than the bin folder. Best of luck, sorry I can't help more from a far.

ManuelSchneid3r commented 3 years ago

Hi @mwidjaja1, I set up my env as you described. I encountered some nonblocking problems.

(gpu-env) ~ pip check
tensorflow-macos 0.1a3 has requirement gast==0.3.3, but you have gast 0.4.0.
tensorflow-macos 0.1a3 has requirement grpcio~=1.32.0, but you have grpcio 1.37.0.
tensorflow-macos 0.1a3 has requirement h5py~=2.10.0, but you have h5py 3.2.1.
tensorflow-macos 0.1a3 has requirement numpy~=1.19.2, but you have numpy 1.20.2.
tensorflow-macos 0.1a3 has requirement protobuf~=3.13.0, but you have protobuf 3.15.8.
tensorflow-macos 0.1a3 has requirement tensorflow-estimator~=2.3.0, but you have tensorflow-estimator 2.4.0.

Ain't this a problem?

Futhrer my setup seems to ignore the GPU.

Bildschirmfoto 2021-04-27 um 10 25 05

Bildschirmfoto 2021-04-27 um 10 26 56Bildschirmfoto 2021-04-27 um 10 26 57

How can I make tensorflow use the GPU instead of the CPU?

This is the cifar10 script to test tensor flow which also reveals that tensorflow does not see the GPU at all.

import tensorflow as tf
print(tf.__version__)
tf.compat.v1.disable_eager_execution()
print(tf.config.list_physical_devices())
from tensorflow.python.client import device_lib
print([x.name for x in device_lib.list_local_devices() if x.device_type == 'GPU'])
from tensorflow.python.compiler.mlcompute import mlcompute
print("is_apple_mlc_enabled %s" % mlcompute.is_apple_mlc_enabled())
print("is_tf_compiled_with_apple_mlc %s" % mlcompute.is_tf_compiled_with_apple_mlc())
from tensorflow.keras import datasets, layers, models

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()
train_images, test_images = train_images / 255.0, test_images / 255.0
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
               'dog', 'frog', 'horse', 'ship', 'truck']
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10))
model.summary()
model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])
history = model.fit(train_images, train_labels, epochs=10,
                    validation_data=(test_images, test_labels))

What am I doing wrong?

Regards

mwidjaja1 commented 3 years ago

@hoytak have the requirements for Apple's Tensorflow changed?

@ManuelSchneid3r for your second issue, please make a new GitLab issue (or search the issues list... I'd be surprised if you're the only one having this problem) for the CPU vs. GPU question. This Gitlab issue is specifically for conda installation.

ManuelSchneid3r commented 3 years ago

@mwidjaja1 indeed there are open issues concerning the GPU. I followed your instructions for conda. Does you setup use the CPU? I mean I should get GPU acceleration if you do right?

CarGod commented 3 years ago

If you get a mistake: ERROR: grpcio-1.33.2-cp38-cp38-macosx_10_16_arm64.whl is not a supported wheel on this platform.

you need to uninstall conda and install: https://github.com/conda-forge/miniforge#miniforge3

johnnynunez commented 3 years ago

Python 3.9 is native with Big Sur and TensorFlow v2.5.0rc2 supports python 3.9... I have checked the binaries one by one that is ARM-compatible in version 3.9. If there are problems with pip just downgrade to version 19.0.3 If you can't install, use brew install numpy, pandas... https://github.com/apple/tensorflow_macos/pull/250

HiLiHeYi commented 3 years ago

Hey, first of all, thanks for the instruction it works for me(pic 1). But once I try to run pip install requirement.txt which requires tensorflow>=2.4.0, it shows me no tensorflow version is available. Can someone help thank you very much

Bildschirmfoto 2021-05-05 um 19 25 23 Bildschirmfoto 2021-05-05 um 19 27 20
mwidjaja1 commented 3 years ago

@HiLiHeYi I think your issue might be better as its own GitLab Issue. I'm just a 'volunteer' monitoring this issue just for Conda installation issues, and this guide has no reference to a requirement.txt file. It sounds like you're having 'other' issues using TensorFlow for your specific Pythonic use case, as opposed to installing TensorFlow, which I see you got working.

However, the version of TF Apple Built, is every so slightly different than what your requirements.txt file wants. Your text file does NOT want a 'beta' release candidate, whereas Apple's is because... well... it is a beta release candidate. You may want to modify your requirements.txt file so it doesn't even mention tensorflow because you already had it installed anyway. I think that should do the trick.

If this doesn't do the trick or doesn't meet your needs, please create a new GitLab issue and tag me so we can discuss there, and keep this clear for Conda install issues. Thanks!

johnnynunez commented 3 years ago

tensorflow v2.5.0 is out. Is it compatible with m1? Support native python 3.9...

JakobLS commented 3 years ago

Failing with installing Miniforge on Mac M1 using brew

If any of those sanity checks failed, you must redo this section. Please ensure that you downloaded the correct Miniforge for your system architecture and installed it. If you did all that, set your environment paths to Miniforge's Python Installation. To do that, you need to figure out where conda was installed to (it's probably ~/miniforge3/condabin/conda) and then run ~/miniforge3/condabin/conda init in your terminal.

My installation was failing on this part. It turned out that Miniforge had been installed to /opt/homebrew/Caskroom/miniforge, so by running /opt/homebrew/Caskroom/miniforge/base/condabin/conda init followed by source .bash_profile solved the problem for me.

mwidjaja1 commented 3 years ago

Hey @JakobLS, while I'm glad you figured it out, I'm super curious how your Homebrew got installed to caskroom. I... don't think that was possible. Do you recall manually requiring miniforge to save there or did it just happen?

Glad you figured it out though, that is the absolute right step! Thanks for sharing

JakobLS commented 3 years ago

Hi @mwidjaja1. Thank you so much for supporting the community. I don't recall the exact details, but I'm pretty sure I didn't manually specify miniforge to be installed at a certain location, nor with Homebrew. I followed your steps in the top, but chose to install miniforge using Homebrew purely for convenience (rather than downloading it first).

And this tutorial was very useful to install Homebrew with.

I had to add export PATH=$PATH:/opt/homebrew/bin and export PATH="/opt/homebrew/Caskroom/miniforge/base:$PATH" to .bash_profile for Homebrew and miniforge respectively though.

Running on MacOS Big Sur 11.3.1