jeffheaton / t81_558_deep_learning

T81-558: Keras - Applications of Deep Neural Networks @Washington University in St. Louis
https://sites.wustl.edu/jeffheaton/t81-558/
Other
5.71k stars 3.04k forks source link

Tensorflow not found after setup #110

Closed theAnshulGupta closed 3 years ago

theAnshulGupta commented 3 years ago

Hey! I've been trying to set up Tensorflow on my M1 Mac following these instructions but have been unsuccessful in doing so.


I followed the entire setup process, but when running the test code with Jupyter Notebook, I got the following error:

(base) Anshul@Anshuls-MacBook-Pro ML % conda env create -f tensorflow-apple-metal.yml -n tensorflow

Collecting package metadata (repodata.json): done
Solving environment: failed

ResolvePackageNotFound: 
  - apple::tensorflow-deps

After some googling, I moved - apple::tensorflow-deps below pip, and reran this line of code. It installed all the dependencies and displayed an error at the bottom:

Here's what my terminal displayed
``` (base) Anshul@Anshuls-MacBook-Pro ML % conda env create -f tensorflow-apple-metal.yml -n tensorflow Collecting package metadata (repodata.json): done Solving environment: failed ResolvePackageNotFound: - apple::tensorflow-deps (base) Anshul@Anshuls-MacBook-Pro ML % conda env create -f tensorflow-apple-metal.yml -n tensorflow Collecting package metadata (repodata.json): done Solving environment: done Downloading and Extracting Packages scikit-learn-0.24.2 | 5.0 MB | ################################################################################################################################################################################################################################### | 100% pillow-8.3.1 | 602 KB | ################################################################################################################################################################################################################################### | 100% numpy-1.20.3 | 23 KB | ################################################################################################################################################################################################################################### | 100% jupyter-1.0.0 | 8 KB | ################################################################################################################################################################################################################################### | 100% pyzmq-20.0.0 | 405 KB | ################################################################################################################################################################################################################################### | 100% packaging-21.0 | 36 KB | ################################################################################################################################################################################################################################### | 100% brotlipy-0.7.0 | 333 KB | ################################################################################################################################################################################################################################### | 100% pyrsistent-0.18.0 | 89 KB | ################################################################################################################################################################################################################################### | 100% scipy-1.6.2 | 14.7 MB | ################################################################################################################################################################################################################################### | 100% hdf5-1.10.6 | 3.0 MB | ################################################################################################################################################################################################################################### | 100% jupyter_core-4.7.1 | 68 KB | ################################################################################################################################################################################################################################### | 100% pandas-datareader-0. | 71 KB | ################################################################################################################################################################################################################################### | 100% setuptools-52.0.0 | 724 KB | ################################################################################################################################################################################################################################### | 100% prometheus_client-0. | 47 KB | ################################################################################################################################################################################################################################### | 100% pyqt-5.9.2 | 3.7 MB | ################################################################################################################################################################################################################################### | 100% pysocks-1.7.1 | 31 KB | ################################################################################################################################################################################################################################### | 100% ipykernel-5.3.4 | 180 KB | ################################################################################################################################################################################################################################### | 100% lz4-c-1.9.3 | 140 KB | ################################################################################################################################################################################################################################### | 100% libxml2-2.9.12 | 1.1 MB | ################################################################################################################################################################################################################################### | 100% cryptography-3.4.7 | 693 KB | ################################################################################################################################################################################################################################### | 100% intel-openmp-2021.3. | 950 KB | ################################################################################################################################################################################################################################### | 100% widgetsnbextension-3 | 863 KB | ################################################################################################################################################################################################################################### | 100% terminado-0.9.4 | 25 KB | ################################################################################################################################################################################################################################### | 100% attrs-21.2.0 | 46 KB | ################################################################################################################################################################################################################################### | 100% botocore-1.20.109 | 3.8 MB | ################################################################################################################################################################################################################################### | 100% six-1.16.0 | 18 KB | ################################################################################################################################################################################################################################### | 100% h5py-3.2.1 | 946 KB | ################################################################################################################################################################################################################################### | 100% boto3-1.17.109 | 70 KB | ################################################################################################################################################################################################################################### | 100% pygments-2.9.0 | 721 KB | ################################################################################################################################################################################################################################### | 100% markupsafe-2.0.1 | 20 KB | ################################################################################################################################################################################################################################### | 100% bottleneck-1.3.2 | 111 KB | ################################################################################################################################################################################################################################### | 100% mistune-0.8.4 | 57 KB | ################################################################################################################################################################################################################################### | 100% pyyaml-5.4.1 | 170 KB | ################################################################################################################################################################################################################################### | 100% pandocfilters-1.4.3 | 14 KB | ################################################################################################################################################################################################################################### | 100% chardet-4.0.0 | 195 KB | ################################################################################################################################################################################################################################### | 100% bleach-4.0.0 | 113 KB | ################################################################################################################################################################################################################################### | 100% click-8.0.1 | 79 KB | ################################################################################################################################################################################################################################### | 100% s3transfer-0.4.2 | 62 KB | ################################################################################################################################################################################################################################### | 100% zstd-1.4.9 | 476 KB | ################################################################################################################################################################################################################################### | 100% parso-0.8.2 | 69 KB | ################################################################################################################################################################################################################################### | 100% brotli-1.0.9 | 398 KB | ################################################################################################################################################################################################################################### | 100% mkl_fft-1.3.0 | 167 KB | ################################################################################################################################################################################################################################### | 100% testpath-0.5.0 | 81 KB | ################################################################################################################################################################################################################################### | 100% webencodings-0.5.1 | 20 KB | ################################################################################################################################################################################################################################### | 100% numexpr-2.7.3 | 124 KB | ################################################################################################################################################################################################################################### | 100% certifi-2021.5.30 | 138 KB | ################################################################################################################################################################################################################################### | 100% zipp-3.5.0 | 13 KB | ################################################################################################################################################################################################################################### | 100% pip-21.2.2 | 1.8 MB | ################################################################################################################################################################################################################################### | 100% mkl-2021.3.0 | 100.4 MB | ################################################################################################################################################################################################################################### | 100% tzdata-2021a | 108 KB | ################################################################################################################################################################################################################################### | 100% sqlite-3.36.0 | 1.1 MB | ################################################################################################################################################################################################################################### | 100% mkl_random-1.2.2 | 285 KB | ################################################################################################################################################################################################################################### | 100% cycler-0.10.0 | 16 KB | ################################################################################################################################################################################################################################### | 100% matplotlib-3.4.2 | 26 KB | ################################################################################################################################################################################################################################### | 100% ca-certificates-2021 | 113 KB | ################################################################################################################################################################################################################################### | 100% cached-property-1.5. | 11 KB | ################################################################################################################################################################################################################################### | 100% threadpoolctl-2.2.0 | 16 KB | ################################################################################################################################################################################################################################### | 100% numpy-base-1.20.3 | 4.3 MB | ################################################################################################################################################################################################################################### | 100% itsdangerous-2.0.1 | 18 KB | ################################################################################################################################################################################################################################### | 100% python-3.9.6 | 9.7 MB | ################################################################################################################################################################################################################################### | 100% nbconvert-6.1.0 | 484 KB | ################################################################################################################################################################################################################################### | 100% tornado-6.1 | 587 KB | ################################################################################################################################################################################################################################### | 100% mkl-service-2.4.0 | 45 KB | ################################################################################################################################################################################################################################### | 100% munkres-1.1.4 | 13 KB | ################################################################################################################################################################################################################################### | 100% matplotlib-inline-0. | 12 KB | ################################################################################################################################################################################################################################### | 100% jinja2-3.0.1 | 110 KB | ################################################################################################################################################################################################################################### | 100% jedi-0.18.0 | 909 KB | ################################################################################################################################################################################################################################### | 100% lxml-4.6.3 | 1.2 MB | ################################################################################################################################################################################################################################### | 100% pandas-1.3.1 | 9.2 MB | ################################################################################################################################################################################################################################### | 100% fonttools-4.25.0 | 632 KB | ################################################################################################################################################################################################################################### | 100% tqdm-4.62.0 | 83 KB | ################################################################################################################################################################################################################################### | 100% matplotlib-base-3.4. | 5.6 MB | ################################################################################################################################################################################################################################### | 100% sip-4.19.13 | 243 KB | ################################################################################################################################################################################################################################### | 100% cffi-1.14.6 | 215 KB | ################################################################################################################################################################################################################################### | 100% openjpeg-2.3.0 | 281 KB | ################################################################################################################################################################################################################################### | 100% python-dateutil-2.8. | 233 KB | ################################################################################################################################################################################################################################### | 100% qtconsole-5.1.0 | 98 KB | ################################################################################################################################################################################################################################### | 100% notebook-6.4.1 | 4.1 MB | ################################################################################################################################################################################################################################### | 100% importlib-metadata-3 | 33 KB | ################################################################################################################################################################################################################################### | 100% jmespath-0.10.0 | 23 KB | ################################################################################################################################################################################################################################### | 100% urllib3-1.26.6 | 112 KB | ################################################################################################################################################################################################################################### | 100% decorator-5.0.9 | 12 KB | ################################################################################################################################################################################################################################### | 100% entrypoints-0.3 | 12 KB | ################################################################################################################################################################################################################################### | 100% appnope-0.1.2 | 10 KB | ################################################################################################################################################################################################################################### | 100% ipython-7.26.0 | 996 KB | ################################################################################################################################################################################################################################### | 100% argon2-cffi-20.1.0 | 44 KB | ################################################################################################################################################################################################################################### | 100% kiwisolver-1.3.1 | 53 KB | ################################################################################################################################################################################################################################### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: | Installed package of scikit-learn can be accelerated using scikit-learn-intelex. More details are available here: https://intel.github.io/scikit-learn-intelex For example: $ conda install scikit-learn-intelex $ python -m sklearnex my_application.py done Installing pip dependencies: / Ran pip subprocess with arguments: ['/opt/anaconda3/envs/tensorflow/bin/python', '-m', 'pip', 'install', '-U', '-r', '/Users/Anshul/Documents/ML/condaenv.u702ztn8.requirements.txt'] Pip subprocess output: Pip subprocess error: ERROR: Invalid requirement: 'apple::tensorflow-deps' (from line 6 of /Users/Anshul/Documents/ML/condaenv.u702ztn8.requirements.txt) failed CondaEnvException: Pip failed ```


After installing this, I went along with the rest of the installation process, and had a few more errors along the way. Here's my terminal input and output:

(base) Anshul@Anshuls-MacBook-Pro ML % conda env create -f tensorflow-apple-metal.yml -n tensorflow

CondaValueError: prefix already exists: /opt/anaconda3/envs/tensorflow

(base) Anshul@Anshuls-MacBook-Pro ML % conda activate tensorflow
(tensorflow) Anshul@Anshuls-MacBook-Pro ML % conda install nb_conda
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / 
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed                                                                                                                                                                                                                                                                        

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - nb_conda -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.8,<3.9.0a0|>=3.5,<3.6.0a0']

Your python: python=3.9

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

(tensorflow) Anshul@Anshuls-MacBook-Pro ML % python -m ipykernel install --user --name tensorflow --display-name "Python 3.9 (tensorflow)"

Installed kernelspec tensorflow in /Users/Anshul/Library/Jupyter/kernels/tensorflow
(tensorflow) Anshul@Anshuls-MacBook-Pro ML % jupyter notebook

Jupyter Notebook is able to run, but once I create a new tensorflow notebook and run the example code, I get the error ModuleNotFoundError: No module named 'tensorflow'.

I've spent the past few hours trying to set up Tensorflow on my M1 Mac, and any help would be amazing. Thanks!

jeffheaton commented 3 years ago

Unfortunately, I do not have a great deal of experience tracking down individual problems (yet) in M1. Unless my computer is doing it, it can be difficult for me to offer much help. So this will be a bit general, you may have better luck with the official support channels for TensorFlow M1.

I would suggest making sure you have the correct conda environment selected. Its a basic suggestion, but I've seen it give many issues.

Secondly, conda activate your environment and just launch python and see if you can "import tensorflow".

theAnshulGupta commented 3 years ago

Thank you! I have contacted the Tensorflow team for assistance.