Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not import tensorflow package #16

Open
Tyzzzzzzzz opened this issue Apr 1, 2023 · 2 comments
Open

can not import tensorflow package #16

Tyzzzzzzzz opened this issue Apr 1, 2023 · 2 comments

Comments

@Tyzzzzzzzz
Copy link


RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf


ImportError Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

SystemError Traceback (most recent call last)
SystemError: <built-in method contains of dict object at 0x138a8b6c0> returned a result with an error set

The above exception was the direct cause of the following exception:

ImportError Traceback (most recent call last)
Cell In[18], line 1
----> 1 import tensorflow as tf
2 print('done')
5 # Check for TensorFlow GPU access

File ~/tensorflow-test/env/lib/python3.8/site-packages/tensorflow/init.py:37
34 import sys as _sys
35 import typing as _typing
---> 37 from tensorflow.python.tools import module_util as _module_util
38 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader
40 # Make sure code inside the TensorFlow codebase can use tf2.enabled() at import.

File ~/tensorflow-test/env/lib/python3.8/site-packages/tensorflow/python/init.py:37
29 # We aim to keep this file minimal and ideally remove completely.
30 # If you are adding a new file with @tf_export decorators,
31 # import it in modules_with_exports.py instead.
32
33 # go/tf-wildcard-import
34 # pylint: disable=wildcard-import,g-bad-import-order,g-import-not-at-top
36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
---> 37 from tensorflow.python.eager import context
39 # pylint: enable=wildcard-import
40
41 # Bring in subpackages.
42 from tensorflow.python import data

File ~/tensorflow-test/env/lib/python3.8/site-packages/tensorflow/python/eager/context.py:33
31 from tensorflow.python import pywrap_tfe
32 from tensorflow.python import tf2
---> 33 from tensorflow.python.client import pywrap_tf_session
34 from tensorflow.python.eager import executor
35 from tensorflow.python.eager import monitoring

File ~/tensorflow-test/env/lib/python3.8/site-packages/tensorflow/python/client/pywrap_tf_session.py:19
17 # pylint: disable=invalid-import-order,g-bad-import-order, wildcard-import, unused-import
18 from tensorflow.python import pywrap_tensorflow
---> 19 from tensorflow.python.client._pywrap_tf_session import *
20 from tensorflow.python.client._pywrap_tf_session import _TF_SetTarget
21 from tensorflow.python.client._pywrap_tf_session import _TF_SetConfig

ImportError: initialization failed

@pradivGnanaraj
Copy link

Im having this error as well. On further checking I noticed the following :

tensorflow-macos 2.12.0 requires h5py>=2.9.0, which is not installed. tensorflow-datasets 4.8.3 requires toml, which is not installed. tensorflow-macos 2.12.0 requires numpy<1.24,>=1.22, but you have numpy 1.24.2 which is incompatible.

Therefore, I had h5py installed:

conda install -c conda-forge h5py

I did not install numpy since it was a part of "tensorflow-deps".

But the issue still exists.

@pradivGnanaraj
Copy link

pradivGnanaraj commented Apr 3, 2023

Okay so I was able to re-create this issue and resolve it successfully.

The steps are more or less the same, except for few :

Download the command line installer from 64-Bit (M1) Command Line Installer (565 MB)

bash Anaconda3-2023.03-MacOSX-arm64.sh

conda list
if the above doesn't work then try (In my case, since mini forge was installed previously, the conda was unable to source, therefore had to source it using bash) :
bash

conda init copy the path, in my case it was

/Users/pradivgnanaraj/anaconda3/bin/activate

Next Step : source /Users/pradivgnanaraj/anaconda3/bin/activate

If error throws up, then try :

sudo rm -rf /Library/Developer/CommandLineTools xcode-select --install

Next Steps : echo $PATH

cd /Users/pradivgnanaraj/anaconda3

conda install -c apple tensorflow-deps

pip install tensorflow-macos

pip install tensorflow-metal

pip install numpy --upgrade

pip install pandas --upgrade

pip install matplotlib --upgrade

pip install scikit-learn --upgrade

pip install scipy --upgrade

pip install plotly --upgrade

RESULTS

`(base) pradivgnanaraj@Pradivs-MacBook-Air ~ % python
Python 3.10.9 (main, Mar 1 2023, 12:20:14) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import platform
platform.platform()
'macOS-13.3-arm64-arm-64bit'`

`>>> import tensorflow as tf

tf.version
'2.12.0'`

`>>> tf.config.list_physical_devices("GPU")
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

`

Hope this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants