1
votes

i tried import keras but it says:

import keras Using TensorFlow backend. Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/keras/init.py", line 3, in from . import utils File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/keras/utils/init.py", line 6, in from . import conv_utils File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/keras/utils/conv_utils.py", line 9, in from .. import backend as K File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/keras/backend/init.py", line 89, in from .tensorflow_backend import * File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site- packages/keras/backend/tensorflow_backend.py", line 5, in import tensorflow as tf File "/Users/elanchezhian/tensorflow.py", line 2, in from tensorflow.examples.tutorials.mnist import input_data ModuleNotFoundError: No module named 'tensorflow.examples'; 'tensorflow' is not a package

i am using mac os high sierra and i am running keras in python3 and i installed keras with pip

edit: ok ,i already had a file named tensorflow.py ,i removed it and new error came

Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/init.py", line 3, in from . import utils File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/utils/init.py", line 6, in from . import conv_utils File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in from .. import backend as K File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/init.py", line 89, in from .tensorflow_backend import * File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 5, in import tensorflow as tf ImportError: bad magic number in 'tensorflow': b'\x03\xf3\r\n'

edit: i have removed tensorflow.pyc now this error came :

RuntimeError: module compiled against API version 0xc but this version 
of 
numpy is 0xb
ImportError: numpy.core.multiarray failed to import
ImportError: numpy.core.umath failed to import
ImportError: numpy.core.umath failed to import
2018-10-21 10:53:26.723451: F 
tensorflow/python/lib/core/bfloat16.cc:675] 
Check failed: PyBfloat16_Type.tp_base != nullptr 
Abort trap: 6
2
try to install tensorflow pip install tensorflow if you didn't already, because keras use it as backendxyz
i already did, but i did it once to check ,but ,it still didnt workuser8618419

2 Answers

1
votes

Your script is named tensorflow.py, which conflicts with the name of the real tensorflow package. Name your script something else.

0
votes

How about generate new virtualenv than 'tensorflow'? I recommend to generate new virtualenv named 'venv' for example. In my Anaconda environment, I have same problem but after generating new one, it solved.

when generate 'tensorflow' virtualenv, I had same moduleerror like you.

$ conda create -n venv pip python=3.6
$ source activate venv
(venv)$

But after generating new virtualenv, it works successfully. I hope your code will work successfully too.