0

My code:

import numpy as np

import tensorflow

Output:

NameError                                 Traceback (most recent call last)
< ipython-input-1-87dbf2ff9b36 > in < module >
----> 1 x = np.random.randint(0,100)

NameError: name 'np' is not defined

What I don't understand is that even though I have already imported the library it is not getting detected and gives me a NameError, Same is the case with a lot of libraries.

I am currently using Jupyter Lab through Anaconda.

=================================>

Got the solution for all the Issues while installing TensorFlow on M1 Macbook

Follow the below link:

https://naturale0.github.io/machine%20learning/setting-up-m1-mac-for-both-tensorflow-and-pytorch#:~:text=Macs%20with%20ARM64%2Dbased%20M1,both%20from%20consumers%20and%20developers.

1 Answers1

1

Thank you @Akella Niranjan for the reference. For the benefit of community providing solution here as written by @Sihyung Park.

Install TensorFlow-macOS for Apple Silicon M1

It is easy to install it with the system python since the installation script is given by Apple. However, my goal was to install it with other python so that I can install additional packages for data science without difficulty.

I mainly followed instructions from here to install tensorflow-macos, and then created ipykernel of it so that I can run this environment any time by switching the kernel inside jupyter notebook.

  1. First install miniforge, which natively supports M1. The installation defaults to directory ~/miniforge3/.

  2. Create virtual environment named tf_macos with conda and install Python 3.8.

    conda create -n tf_macos
    conda activate tf_macos
    conda install -y python=3.8
    

I specified the version 3.8 so that it matches requirement of tensorflow-macos.

  1. Download and install tensorflow-macos from Apple Github.
git clone https://github.com/apple/tensorflow_macos.git
cd tensorflow_macos/arm64
pip install --force pip==20.2.4 wheel setuptools cached-property six
pip install --upgrade --no-dependencies --force numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl tensorflow_addons-0.11.2+mlcompute-cp38-cp38-macosx_11_0_arm64.whl
pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard
pip install --upgrade --force --no-dependencies tensorflow_macos-0.1a1-cp38-cp38-macosx_11_0_arm64.whl
  1. Add the environment as jupyter kernel.
pip install jupyter
python -m ipykernel install --name=tf_macos

Then merely switching the ipython kernel to tf_macos allows us to use mlcompute-backend TensorFlow without a hassle

  1. Install additional packages (optional)
conda install scipy pandas matplotlib

For more information you can refer here