apple / tensorflow_macos

TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Instructions to install TensorFlow in a Conda Environment

mwidjaja1 opened this issue · comments

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:

  • Run file $(which python) in your terminal (thanks to @lebigot for this shortcut!). Please make sure that you got:
    • This path implies you're running your miniforge version of Python. It'll probably be <your home dir>/miniforge3/bin/python.
    • If you have an Apple Silicon Mac, it should also say Mach-O 64-bit executable arm64. If you have an Intel Mac, it should also say Mach-O 64-bit executable x86_64.
  • Run which pip in your terminal and it too should resolve to some path that implies you're using miniforge3.

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

  • Type in which python and then which pip in your terminal. Both paths should point to a Python that is inside the environment you created in Step 2. If it doesn't, you may not have installed Miniforge correctly, ran Step 2 correctly, and/or may not have ran Step 3.
  • Run python --version and it should be version 3.8. If it isn't, you most likely did not create or activate your environment correctly, as per Steps 2 & 3. Do those again.
  • If python is correctly pointed to the right environment but you cannot import tensorflow, consider running step 5 again just to make sure you installed Tensorflow in the appropriate environment.
  • If you are using Intel and got a not a supported wheel on this platform error, run export SYSTEM_VERSION_COMPAT=0 in your terminal and try again. If this works, you'll need to do this everytime you use Python until a Python Bug is resolved.
  • Please verify that you did ALL of the Sanity Checks from the previous section and that they resolve appropriately before posting your issue here. If you do post your issue, please provide the terminal outputs from those steps and bonus points if you share the results of your Sanity Check and run pip with a -v flag for additional logging. Remember I'm just a volunteer -- I'll try to help but there's only so much I can help with.

Troubleshooting for setting up TensorFlow

  • For those having issues with tf.keras.models.load_model about a failed to decode error: Try downgrading to h5py to the 2.10.0 wheel file that was packaged with this alpha release (pip install ~/path to h5py.whl). Thanks to @ramicaza.

I couldn't install the wheels without renaming them to read "...-macosx_10_16_..." instead of "...-macosx_11_0_..."

@Tioz90 I didn't have that problem. Could you tell me what your Mac's version is? That's Apple (in the Menu Bar) > About my Mac. Mine is Version 11.2.

@Tioz90 You may want to create a new issue then about this. I'm not on the team working on this, I just wrote up these instructions as a 'side contributor' with their help.

I think it's a known issue with pip

That's an interesting thought @Tioz90 -- My pip version is 20.2.4 which I checked by running pip --version. If yours isn't that version, could you get that version and try again?

Mine is 21.0.1 and it still does not work..

@Tioz90 I cannot reproduce your issue. I've upgraded to the same pip version you had, trashed my environment, and was able to successfully rebuild it. I have a hunch somewhere in your Python installation, you're accidentally linking to some other Python that you did not intend to use but I wouldn't know how to begin figuring that out. Glad you got it to work by renaming it though

There's a few things that could make this issue a mess. I haven't found versions of pip later than 20.2.4 to work here; version 20.3 and later actually broke some of the logic. Also, the logic inside of pip is duplicated across setuptools and packaging, both of which are baked into the core python distribution; upgrading these might help, but your mileage may vary.

Does it mean that installing TensorFlow in a Conda Environment allows m1 chip to use tensorflow with SciPy and dependent packages?

I got this Error
ERROR: tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.
This is my System Information:

  • python: /Users/gyuannn/miniforge3/envs/test/bin/python, 3.8.6
  • pip: /Users/gyuannn/miniforge3/envs/test/bin/pip, 20.2.4
  • System: MacOS11.2
  • Laptop: MBP16,2019
  • Run command on Conda Env builded from environment.yml

I'm Confused... 

Run python -m pip debug --verboseand
find pip not support cp38-cp38-macosx_11_0_x86_64 only support cp38-cp38-macosx_10_16_x86_64

Indeed:
Python 3.8 from the system:

/usr/bin/python3 -c "import platform; print(platform.platform())"
macOS-11.0.1-x86_64-i386-64bit

Python 3.9 installed with homebrew:

/usr/local/bin/python3 -c "import platform; print(platform.platform())"
macOS-11.0.1-x86_64-i386-64bit

Python 3.8 from a conda-forge env:

/Users/ogrisel/miniforge3/envs/py38/bin/python -c "import platform; print(platform.platform())"
macOS-10.16-x86_64-i386-64bit

So conda-forge's Python is indeed pretending to be installed on a fake 10.16 version of macOS to bypass this problem with pip 20.2.4.

@Tioz90, I think @gyuannnn figured it out. I get your exact error on Anaconda on Intel too. Interestingly enough on an identical macOS version on an Apple Silicon Mac, it actually is 11_0. So it looks like it's all Conda Pythons (since I tried on Anaconda and you tried Miniforge) on Big Sur Intel, the platform is being saved as 10_16 rather than 11_0.

Not sure how to report this to the Miniforge folks but I can poke around unless you have an idea where the problem might be. In the meanwhile, can you try downloading the wheel files and renaming it so instead of having 11_0 in the two wheel file names, it says 10_16 instead and try pip installing those? If that works, I'll update the Readme for this workaround.

@hoytak tagging you for situational awareness that we figured out the issue.

EDIT: Nevermind I see you reported it already. https://github.com/conda-forge/miniforge/issues/105. Not sure if this is the right place admittedly (it could be Conda's fault) but let's see if they know where to direct us to.

@Tioz90, I think @gyuannnn figured it out. I get your exact error on Anaconda on Intel too. Interestingly enough on an identical macOS version on an Apple Silicon Mac, it actually is 11_0. So it looks like it's all Conda Pythons (since I tried on Anaconda and you tried Miniforge) on Big Sur Intel, the platform is being saved as 10_16 rather than 11_0.

Not sure how to report this to the Miniforge folks but I can poke around unless you have an idea where the problem might be. In the meanwhile, can you try downloading the wheel files and renaming it so instead of having 11_0 in the two wheel file names, it says 10_16 instead and try pip installing those? If that works, I'll update the Readme for this workaround.

@hoytak tagging you for situational awareness that we figured out the issue.

EDIT: Nevermind I see you reported it already. conda-forge/miniforge#105. Not sure if this is the right place admittedly (it could be Conda's fault) but let's see if they know where to direct us to.

Downloaded and renamed it to 10_16_ works fine.

@mwidjaja1
according to conda-forge/miniforge#105
export SYSTEM_VERSION_COMPAT=0 before running python (on env) can set it to 11_0_

@Tioz90, I think @gyuannnn figured it out. I get your exact error on Anaconda on Intel too. Interestingly enough on an identical macOS version on an Apple Silicon Mac, it actually is 11_0. So it looks like it's all Conda Pythons (since I tried on Anaconda and you tried Miniforge) on Big Sur Intel, the platform is being saved as 10_16 rather than 11_0.

Not sure how to report this to the Miniforge folks but I can poke around unless you have an idea where the problem might be. In the meanwhile, can you try downloading the wheel files and renaming it so instead of having 11_0 in the two wheel file names, it says 10_16 instead and try pip installing those? If that works, I'll update the Readme for this workaround.

@hoytak tagging you for situational awareness that we figured out the issue.

EDIT: Nevermind I see you reported it already. conda-forge/miniforge#105. Not sure if this is the right place admittedly (it could be Conda's fault) but let's see if they know where to direct us to.

Yes, renaming the files installs them without an issue

@gyuannnn Thanks for the heads up, I updated the documentation to reflect this temporary workaround. Python 3.8.8 sounds like it'll fix this issue fortunately.

Conversely, renaming the files may crash your Python @Tioz90 if you ever update your Python to 3.8.8 which is planned to fix this issue. https://www.python.org/downloads/release/python-387/

@hoytak A heads up for your team's awareness that this is an issue... and actually might explain some of the crazy pip commands I noticed you guys pulling off. I'm starting to wonder if some of the weird installation issues I saw, while trying to use Conda installs to setup TensorFlow's pre-reqs, were related to this whole 10_16 vs. 11_0 mishap.

How can I "point" python and pip to use their respective miniforge versions? I have my conda environment working fine, but when I enter which python and which pip I get /usr/bin/python and /usr/bin/pip respectively.

I tried installing as above but got the wheel error:
ERROR: tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.

How can I "point" python and pip to use their respective miniforge versions? I have my conda environment working fine, but when I enter which python and which pip I get /usr/bin/python and /usr/bin/pip respectively.

I tried installing as above but got the wheel error:
ERROR: tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_x86_64.whl is not a supported wheel on this platform.

+1 Ran into the exact same issue today.

@icenando & @mathieuboudreau this means Miniforge is not added to your system path. This is usually a Googling task just because everybody's terminals shell prompts are different, it'd be way beyond the scope of this post to cover every permutation.

In theory running conda init in your terminal should fix it. If it complains it cannot find conda, that means you need to figure out where you installed it to and run this command again from that directory where conda resides. If that doesn't work you'll need to identify where the Python executable that Miniforge installed is, than figure out what Shell Language your terminal is using by running echo $SHELL, and then Googling how you'd add the directory containing Python to your system paths environment variable.

@mwidjaja1 Thank you for that. conda init sorted the python and pip issues, but I'm still getting ERROR: grpcio-1.33.2-cp38-cp38-macosx_10_16_arm64.whl is not a supported wheel on this platform. (I tried renaming the file to 10_16 like others recommened).

I notice that the python version installed with miniforge is 3.9. So I tried changing the pip install line to python3.9 instead of 3.8, but I got the same wheel error.

When I try using Apple's .sh file, ERROR: Python version in specificed virtual environment /Users/nandom/miniforge3/envs/TF not 3.8. Python 3.8 required for tensorflow_macos 0.1a2. .

Any help to sort this out would be appreciated.

Ok, so removing the evironment and re-creating it, specifying python=3.8 solved it. There were other steps that I had to adapt. This post is the only thing that actually worked (I had to change the filenames in the pip installs, as they have changed since it was written): https://claytonpilat.medium.com/tutorial-tensorflow-on-an-m1-mac-using-jupyter-notebooks-and-miniforge-dbb0ef67bf90

@icenando I'm glad you got it working though just to get feedback, I'm not sure why that article would work whereas these notes wouldn't. "Installing TensorFlow" section of this guide tells you to download environment.yml and then activate said environment. That environment is designed to give you Python 3.8 and all of the prerequisites you need.

With all due respect, your first comment implies you didn't read my instructions, because you're right miniforge installs Python 3.9 by default but my instructions literally guide you away from using it. But if you have any error messages while setting up that environment or activating it, please let me know, I'd be glad to rephrase the guide. Thanks.

@mwidjaja1 Sorry, I didn't mean to imply that your instructions are incorrect. I'm sure I'm making a lot of mistakes as I go: I'm not that experienced, and there are a lot of instructions that I follow blindly because I don't understand what they do.

I don't remember getting any error messages prior to the wheel one. But regardless, that meant that I was unable to finish the install. Not that I know what I'm talking about, but wouldn't it be good to replace conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME_HERE with conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME_HERE python=3.8, just to be sure that the correct version is in use in the newly created environment?

The troubleshooting section of that article also covered many of the errors that I was getting, as well as how to install libraries that I was unable to before (I did have a working environment in place before things went pear shaped).

Apologies again if my previous message implied that there was something wrong with your instructions.

@icenando No worries! I've been there too -- I just have been getting more DMs about this and I'm just a 'volunteer' so I've been running around heh.

If you wouldn't mind, could you give the original command another whirl? So long as you name that Conda environment something different than what you did with your working tensorflow env, they shouldn't stomp each other out. Specifically the commands I'm asking you to run are:

conda env create --file=PATH_TO_ENVIRONMENT.YML --name=YOUR_ENV_NAME_HERE
conda activate YOUR_ENV_NAME_HERE
python --version

The YML file you're downloading is the 'recipe' that Conda will use to download everything and set Python up. Because of that, there SHOULD be no need to specify python=3.8 in that command because it's in the environment file. BUT, I could definitely be wrong so if that doesn't work, I'd be glad to look at the error some more.

@mwidjaja1 You are right, the python version is 3.8.6, so that's not what caused the wheel problem. I really don't know what else it could have been... I read somewhere that the order in which things got installed mattered, so maybe that?

@icenando [shrugs] Who knows? Either way I'm glad you got it working somehow! Your questions led to me adding the conda init shoutout to the documentation which I think is a good add anyway, so thanks for accidentally guiding me in that way 🙂

I did everything suggested on here but still can't seem to be able to install it. I still get ERROR: tensorflow_macos-0.1a2-cp38-cp38-macosx_10_16_arm64.whl is not a supported wheel on this platform. Any other suggestions?

@maguileraf can you please run all of the Sanity Checks in the guide (there were several of them) and paste those results here?

Also please try to send me a screenshot of your terminal window, running the same types of commands I ran when I posted my screenshot in the "Example Commands" section.

thanks you.
I was able to run.
I was able to "learn" with MNIST, but tensorflow.keras uses the pillow package to load the image.

from PIL import Image

I get an error.

After multiple attempts all using new clean environments got up to step 5.

On import TensorFlow receive message ModuleNotFoundError: No module named 'flatbuffers'
Seems error occurs running:
.../lib/python3.8/site-packages/tensorflow/lite/python/util.py
However conda list shows flatbuffers version: 1.12.0 build: h9f76cd9_0 channel: conda-forge

This is on a new Apple M1 Air with macOS 11.2.1

I did not create latest environment using file environment.yml
Instead created only including python3.8 then did conda install separately, in order, for each item listed in environment.yml.
For the few items not found by conda install I used pip install.

Previous attempts when environments were created using file environment.yml I got some of the errors mentioned above by others when running step 4. command.

Any suggestions what to try next?

@gosstyla It's my understanding that Apple's Tensorflow is very finicky with the packages it accepts and where it comes from. Conda packages could differ from the Pip packages. My request would be for you to try it again using the environment as per the instructions. If it works, I'd appreciate it if you can file a new issue about flatbuffers in this repo. [Disclaimer: I am just a volunteer on the side who wrote these instructions, my knowledge of the state of Apple's TensorFlow is about 1%]

@taisuke-ito Please file a new issue, that's outside the scope for both this issue (installing via Conda) and my role on the project (I'm just a volunteer). That said I am aware of issues with Keras on ARM so it could be related to that -- I wouldn't be surprised if you just can't use Keras at all right now.

@maguileraf

  • If you run sw_vers -productVersion in your terminal, you should see something like 11.##. If you don't, that's your problem, re-read the instructions in regards to macOS Big Sur.
  • If you are on version 11, please verify that you have an Apple Silicon Mac because you're installing an Apple Silicon only wheel (note: Not all Macbook Pros sold in late 2020 were Apple Silicon).
  • If those two check out, run pip again but also throw in a -v flag for verbose and see if it gives you any additional error messages that guide you in the right direction.

In conda flatbuffers is the C/C++ library. python-flatbuffers is the python library.

I use mambaforge flavor instead of miniforge, so far so good.

mwidjaja1

I did try again - following steps 1-5 exactly including using file environment.yml. IT WORKED!

Thanks, next I'll try actually using tensorflow.

commented

awesome writeup!
just a heads up for those having issues with tf.keras.models.load_model: make sure to downgrade to h5py to the 2.10.0 packaged with the alpha releases (just pip install ~/path to h5py.whl). otherwise you get a 'failed to decode' error

I had installed the wrong Miniconda version for my laptop's architecture. pip command now works without issues

Thanks @ramicaza, I'll add that to the ever growing troubleshooting section and credit you for it

I can't download environment.yml

I can't download environment.yml

That link still works for me, even from a computer that's not signed into my account. If that's actually a problem for you, please provide any error messages or issues you're seeing.

I can't download environment.yml

That link still works for me, even from a computer that's not signed into my account. If that's actually a problem for you, please provide any error messages or issues you're seeing.

Sorry, maybe it's because of the network problem in China. Now it's solved. thank you

Guys, I appreciate all the effort your are putting in this pre-release installation, but many of us have problems on the Apple M1:

pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha2/tensorflow_addons_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl
ERROR: tensorflow_macos-0.1a2-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.

New conda environment, python 3.8.8.

Would you mind giving us a hand not sort this out?

@epignatelli I'm sorry you're running into issues but based on what you sent me, I'm pretty sure you did not follow the Troubleshooting for importing TensorFlow instructions. I (who remember, is just a volunteer), explicitly asked you to provide very specific information when requesting for help to prove that you have followed the entire guide from start to finish.

Please reread the troubleshooting instructions, and once you read all the bullet points in that section, it should be pretty clear on what you need to include here for me to help out more.

Thanks!

Edit: Realized I must have backed it out on a previous edit so that's my fault [sighs at myself], but, please provide the terminal outputs you get while running the troubleshooting section.

Thanks a lot!

The sanity check and troubleshooting sections are a useful idea. :)

Checking the Python interpreter path and architecture could be done more directly with:

> file $(which python)
…/miniforge3/bin/python: Mach-O 64-bit executable arm64

@lebigot thank you for sharing that command! I knew there had to be an easier way but the internet was failing me. I'll update the instructions with your recommendation and give you credit. Many thanks!

Thanks.

Steps 1 and 3 can be merged, too: with file, you get both the path and the type of executable. :)

Hey @mwidjaja1 Kudos for your efforts. Can you please share how your terminal looks that way ?

...I really should have figured that out. Thanks @lebigot

@pra-dan To not flood this issue, I'd appreciate it if we can continue discussions outside of this issue if you have further questions. But to quickly rattle this off

Thanks for putting together the instructions.I just noticed that 0.1a3 is out, so it would be great if you can update your instructions as well. I created the updated one for you:

X86:
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
ARM:
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

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

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

@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 \

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.

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 #153 (comment)
image

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.

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

@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!

@mwidjaja1 The more you write, the more it can be misguided.
I'm a big fan of a script, it explains everything. #153 (comment) could be a blueprint for it

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?

@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.

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.

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 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 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.

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?

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.

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

@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.

Is it not compatible with Python 3.9 version yet?

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

@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

@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:

  • Try creating a brand new empty conda environment, install Python + Pip there, and then try to pip install something. If that works, conda install everything the .yaml file would normally have you install, and then try pip installing TensorFlow again.
  • Are you sure you don't have pip linked to that random site-packages path in the one of the Anaconda bin folders you had in $PATH?
  • Try running grep -ri pip ~ in your terminal -- I'm curious if you have a file that has the word 'pip' in it, linked to something else.
  • The most extreme solution, create a brand new user account on your Mac and try installing Miniforge there. If you're able to get pip working there, it is almost certainly a problem with your original account's Python configuration. I wouldn't know what the issue is, but at least then, you can compare files across both user accounts and start to triage where things might have went wrong.

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.

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

@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.

@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?

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

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...
#250

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

@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!

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

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.

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

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