ImportError with importing keras - python

I am trying to import keras it gives me an error from tensorflow.python.ops import tensor_array_ops.
>>> import keras
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/__init__.py", line 2, in <module>
from . import backend
File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/backend/__init__.py", line 67, in <module>
from .tensorflow_backend import *
File "/home/ss/anaconda2/envs/kerasenv/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 4, in <module>
from tensorflow.python.ops import tensor_array_ops
ImportError: cannot import name tensor_array_ops
I really appreciate if someone can help me to solve this error.
Thanks.

Try: sudo pip install tensorflow --upgrade
You may be using an older version of TensorFlow.

Did you install tensorflow at all?
Could you try installing the lastest version? There is how:
pip install git+git://github.com/tensorflow/tensorflow
pip install git+git://github.com/fchollet/keras.git --upgrade
If this doesn't work I do recommand using theano as a backend, it worked well for me.
There is how to setup it easily:
pip install git+git://github.com/Theano/Theano
pip install git+git://github.com/fchollet/keras.git --upgrade
pip install tensor
Before you do anything else, start python and import keras. Once keras is imported a new file will be created. You can then execute this command:
vi .keras/keras.json
Once the file is open, change tensorflow for theano and you are ready to go.

Related

Cannot install Tensorflow with Pycharm because of Protobuf error

I installed Pycharm for Windows 10
pip install tensorflow went fine without errors
When trying to run a simple project
# Import `tensorflow`
import tensorflow as tf
# Initialize two constants
x1 = tf.constant([1,2,3,4])
x2 = tf.constant([5,6,7,8])
# Multiply
result = tf.multiply(x1, x2)
# Print the result
print(result)
I get the error message
Traceback (most recent call last):
File "C:/Users//PycharmProjects/RiffRam/RiffRam.py", line 2, in <module>
import tensorflow as tf
File "C:\Users\\PycharmProjects\RiffRam\venv\lib\site-packages\tensorflow\__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\\PycharmProjects\RiffRam\venv\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\\PycharmProjects\RiffRam\venv\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "C:\Users\\PycharmProjects\RiffRam\venv\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
Can somebody please tell me how I can get a working installation of Tensorflow, it seems that all the versions are mismatched and pip makes no attempt to install correct versions of each package. I don't care if its outdated.
What commands do I need to type in to get a working stable version from a clean installation of Pycharm so that the code above would run?
Thank you
I got it
pip install --upgrade --force-reinstall setuptools==39.1.0
pip install --upgrade --force-reinstall protobuf==3.6.0
pip install --upgrade --force-reinstall tensorflow==1.11

Error importing tensorflow in Python 3 on Ubuntu 16.04 SyntaxError: l.append("%s=%s" % (attr, `value`))

I have python 3.5 installed on my Linux Mint (Ubuntu 16.04 Xenial)
I also had installed protobuf installed using pip3 install protobuf
I installed tensorflow using pip3 install tensorflow
Then I tried to import tensorflow in python 3 it failed with error presented below:
Traceback (most recent call last):
File "/home/abdullah/face_recognition/tensorflow_test.py", line 1, in <module>
import tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 83, in <module>
from tensorflow.python.estimator import estimator_lib as estimator
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator_lib.py", line 35, in <module>
from tensorflow.python.estimator.inputs import inputs
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/inputs.py", line 22, in <module>
from tensorflow.python.estimator.inputs.numpy_io import numpy_input_fn
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/numpy_io.py", line 22, in <module>
from tensorflow.python.estimator.inputs.queues import feeding_functions
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/inputs/queues/feeding_functions.py", line 40, in <module>
import pandas as pd
File "/usr/local/lib/python3.5/dist-packages/pandas/__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "/usr/local/lib/python3.5/dist-packages/pandas/compat/__init__.py", line 361, in <module>
from dateutil import parser as _date_parser
File "/usr/local/lib/python3.5/dist-packages/dateutil/parser.py", line 158
l.append("%s=%s" % (attr, `value`))
^
SyntaxError: invalid syntax
Consulting through many questions posted on SO and other forums, I tried uninstalling protobuf then I encountered following error.
Traceback (most recent call last):
File "/home/abdullah/face_recognition/tensorflow_test.py", line 1, in <module>
import tensorflow
File "/usr/local/lib/python3.5/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python3.5/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
ImportError: No module named 'google.protobuf'
At the moment I'm just a beginner for all of this. I don't why protobuf is required why do all this hassle? I just wanted to get tensorflow installed on my system and try to learn something.
I was also facing the same problem. The problem I think is this is using pandas from system(apt-get) repository which is not compatible with other libraries. Updating pandas do the trick.
pip3 install --upgrade pandas
Also in your case, if only doing above fails, you can also try to reinstall tensorflow and protobuf with upgrade option.
pip3 install --upgrade protobuf
pip3 install --upgrade tensorflow
I just installed TensorFlow on my system today (Ubuntu 16.04 LTS) using VirtualEnv.
Did you run$ sudo apt-get install python3-pip python3-dev
If so, then try $ pip3 install -upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.0-cp35-cp35m-linux_x86_64.whl
Worst comes to worse, you could simply uninstall TensorFlow using $ sudo pip3 uninstall tensorflow and then try reinstalling to see if it corrects any errors.

TFLearn pip installation bug

I've tried installing tflearn through pip as follows
pip install tflearn
and now when I open python, the following happens:
>>> import tflearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/tflearn/__init__.py", line 22, in <module>
from . import activations
File "//anaconda/lib/python2.7/site-packages/tflearn/activations.py", line 7, in <module>
from . import initializations
File "//anaconda/lib/python2.7/site-packages/tflearn/initializations.py", line 5, in <module>
from tensorflow.contrib.layers.python.layers.initializers import \
ImportError: cannot import name variance_scaling_initializer
Any ideas? I'm using an anaconda installation of python.
The variance_scaling_initializer() function was added on April 19th, which means that it wasn't included in version 0.8.0rc0, and you need to upgrade to a newer version of TensorFlow. If you upgrade to the 0.9.0rc0 version that was released this week, tflearn should work.
Last tflearn update had a compatibility issue with old TensorFlow versions (like mrry said, caused by 'variance_scaling_initializer()' that was only compatible with TensorFlow 0.9).
That error had already been fix, so you can just update TFLearn and it should works fine with any TensorFlow version over 0.7.
This is because your TensorFlow version is too low. Tflearn requires tensorflow‘s version >= 1.0, so you should reinstall tensorflow again, and reinstall step like this:
For python2.7:
sudo pip install tensorflow==1.0 #cpu version
sudo pip install tensorflow-gpu==1.0 # gpu version
For python3:
sudo pip3 install tensorflow==1.0 #cpu version
sudo pip3 install tensorflow-gpu==1.0 # gpu version

Tensorflow pip built from source fails on 'import tensorflow'

Built tensorflow 0.7 from source on Ubuntu 15.10, Cuda 7.5, cudnn 4.0, python 2.7. Bazel build and pip package generation OK. pip install ok. Python script "import tensorflow" fails:
Traceback (most recent call last):
File "/home/keith/Desktop/tf1.py", line 8, in <module>
import tensorflow as tf
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 35, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module>
serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"z\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x12\x14\n\x0cunknown_rank\x18\x03 \x01(\x08\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tB/\n\x18org.tensorflow.frameworkB\x11TensorShapeProtosP\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
Any thoughts?
Thanks
This does look like a protobuf library versioning error. There's a long thread on similar issues here:
https://github.com/tensorflow/tensorflow/issues/11
Towards the end there are some suggested solutions that might help.
I succeed in running TensorFlow 0.7 on a manjaro linux laptop using cuda acceleration by running python with optirun:
$optirun python
However, I had problem with protobuf and I had to uninstall/reinstall previous version of protobuf and tensorflow with pip. http://bit.ly/1RHApU5
This is because of protobuf version conflict:
for me i had python-protobuf v2.6.1 installed from apt-get package manager
and while installing tensorflow it installed protobuf v3.3.0 from pip manager
so i uninstalled both:
sudo pip uninstall protobuf
sudo apt-get remove python-protobuf
Reinstalled using pip and it solved the issue!!!
sudo pip install protobuf
Hope this helps..

Install scikit-learn, numpy import error

I am trying to test scikit-learn library, but didn't manage to install it.
More details : I did install numpy, scipy, matplotlib and I can use them just fine. However, when I use pip (pip install -U scikit-learn), I get this error :
Partial import of sklearn during the build process.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\...\scikit-learn\setup.py", setup_package()
File "C:\Users\...\scikit-learn\setup.py", from numpy.distutils.core import setup
ImportError: No module named 'numpy'
I couldn't find anything about this.
I tried installing scikit-learn directly by using python setup.py and had the same problem. Any ideas?
Thanks you.
I think there are something wrong with the installation of numpy.
Try download and reinstall following package (for Python 2.7):
http://downloads.sourceforge.net/project/numpy/NumPy/1.9.2/numpy-1.9.2-win32-superpack-python2.7.exe?r=&ts=1442420256&use_mirror=netix

Categories

Resources