apple / tensorflow_macos

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

TensorFlow import error #183

Open MeherDeepak-2005 opened 3 years ago

MeherDeepak-2005 commented 3 years ago
Screenshot 2021-03-04 at 3 31 56 PM
atw1020 commented 3 years ago

This is an installation error, you are trying to run a arm64 version of tensorflow in a x86 version of python.

If you run the following in a python shell

>>> import platform
>>> platform.machine()

the above will either output

'x86_64'

or

'arm64'

in order to install the correct version follow these steps: 1) Install tensorflow_macos-0.1alpha3.tar.gz from the releases 2) Untar the archive using the following command

tar xvf tensorflow_macos-0.1alpha3.tar.gz

3) go to the directory that corresponds to the output you got above (x86_64 or arm64) 4) install the wheels stored there (see below)

I see you are using a conda environment so I suggest you refer to #153 and this article for more details about how to install under a conda environment. These will show you how to install the wheels under a conda environment

MeherDeepak-2005 commented 3 years ago

I ran the code in python shell and it gave the following output x86_64 So I installed x86_64.whl instead of arm64.whl files After successfully installing the wheels in a virtual environment instead of anaconda it gave the following error

Screenshot 2021-03-06 at 2 43 23 PM

I tried installing wheel files in anaconda but it gave me the same error

Prashant-Kesharwani commented 3 years ago

You can install all the following modules by creating a Virtual Environment, and then installing all these modules inside that Virtual Environment.

1. Install Matplotlib

1.1 Install Homebrew Type in your terminal (not in rosetta environment):

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Then add homebrew's path to the variable path:

echo 'eval $(/opt/homebrew/bin/brew shellenv)' >> /Users/bcghostpc/.zprofile eval $(/opt/homebrew/bin/brew shellenv)

1.2 Install libjpeg

brew install libjpeg

1.3 Install Matplotlib

In the virtual environment, type:

pip install matplotlib

2. Install tensorflow

Type in terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)" then name your virtual environment's folder

3. Install pandas

In your virtual environment, type:

pip install cython git clone https://github.com/pandas-dev/pandas.git cd pandas python3 setup.py install

4. Install jupyter notebook

In your virtual environment, type:

pip install notebook Then go to lib/python3.8/site-packages/ipykernel

Edit the eventloops.py file using nano eventloops.py

In the _use_appnope() function, edit the return line as follows:

return sys.platform == 'darwin' and V(platform.mac_ver()[0]) >= V('10.9') and platform.mac_ver()[2] != 'arm64'

Appendix

About Installing Different Modules You can install any module using pip inside Virtual Environment:

pip install <moduleName>

About Virtual Environment

You can create a virtual environment by:

python3 -m venv <name> After creating the environment, you can activate the environment by:

source <name>/bin/activate To exit the environment, type:

deactivate