I installed tensorflow using anaconda distribution and I am unable to use the same in python.
When I import tensorflow using import tensorflow I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kaxilnaik/anaconda/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/Users/kaxilnaik/anaconda/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/Users/kaxilnaik/anaconda/lib/python2.7/site-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 "/Users/kaxilnaik/anaconda/lib/python2.7/site-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 "/Users/kaxilnaik/anaconda/lib/python2.7/site-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 "/Users/kaxilnaik/anaconda/lib/python2.7/site-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(\tB2\n\x18org.tensorflow.frameworkB\x11TensorShapeProtosP\x01\xf8\x01\x01\x62\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
I tried reinstalling anaconda as well as uninstalling protobuf which I found as an answer somewhere in stackoverflow.
You should uninstall tensorflow as well, and make sure protobuf is uninstalled. You can try brew uninstall protobuf as well. Then reinstall protobuf, and tensorflow. Tensorflow requires protobuf version 3.x
pip install 'protobuf>=3.0.0a3'
You can test your protobuf version:
import google.protobuf
>>> print google.protobuf.__version__
Related
I am trying to run the quickstart from Google's Vision python library locally. However, when I run python3 quickstart.py I get the following error:
Traceback (most recent call last):
File "/Users/penguin/.../quickstart.py", line 53, in <module>
print(run_quickstart())
File "/Users/penguin/.../quickstart.py", line 25, in run_quickstart
from google.cloud import vision
File "/Users/pengui/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision/__init__.py", line 18, in <module>
from google.cloud.vision_v1.services.image_annotator.async_client import (
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision_v1/__init__.py", line 17, in <module>
from google.cloud.vision_helpers.decorators import add_single_feature_methods
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/cloud/vision_helpers/__init__.py", line 16, in <module>
import proto
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/proto/__init__.py", line 15, in <module>
from .enums import Enum
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/proto/enums.py", line 17, in <module>
from google.protobuf import descriptor_pb2
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/descriptor_pb2.py", line 5, in <module>
from google.protobuf.internal import builder as _builder
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/internal/builder.py", line 42, in <module>
from google.protobuf import reflection as _reflection
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/reflection.py", line 51, in <module>
from google.protobuf import message_factory
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/message_factory.py", line 42, in <module>
from google.protobuf.internal import api_implementation
File "/Users/penguin/anaconda3/envs/vision/lib/python3.9/site-packages/google/protobuf/internal/api_implementation.py", line 104, in <module>
from google.protobuf.pyext import _message
TypeError: bases must be types
What I know is:
This doesn't happen when I run quickstart in the Google CloudShell
I am using the right creds, GOOGLE_APPLICATION_CREDENTIALS=key.json
I am using python 3.9.12 locally
I installed requirements.txt using pip3 (google-cloud-vision==2.7.2)
python3 and pip3 are both in the right /anaconda3/envs/vision path.
My OS is macOS Monterey 12.4
I am not sure at what point in this stack trace that the error is occurring, or how to fix it.
According to #DazWilkin's comment, downgrade the protobuf package as follows.
pip uninstall protobuf
pip install protobuf==3.20.1
It worked just fine for me. tensorflow and protobuf versions were incompatible in my case.
My python version is python3.8.8.
I installed tensorflow2.7 on a linux server.
And when I import tensorflow.keras. It shows error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 41, in <module>
from tensorflow.python.eager import context
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/python/eager/context.py", line 47, in <module>
from tensorflow.python.util.deprecation import deprecated
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/python/util/deprecation.py", line 32, in <module>
from tensorflow.tools.docs import doc_controls
ModuleNotFoundError: No module named 'tensorflow.tools'
I tried to uninstall tensorflow2.7 and install older version tensorflow2.2
the error becomes:
Traceback (most recent call last):
File "cnn_mnist1.py", line 7, in <module>
import tensorflow.keras as keras
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "/research/dept8/msc/xcxia21/anaconda3/lib/python3.8/site-packages/tensorflow/python/__init__.py", line 53, in <module>
from tensorflow.core.framework.graph_pb2 import *
ModuleNotFoundError: No module named 'tensorflow.core'
I am confused about why I need to import tensorflow.tools or tensorflow.core when I only want to import tensorflow.keras?
Someone told me I should build a virtual environment to deal with it. But I would like to know why tensorflow.tools and tensorflow.core are missing?
Besides, when I install tensorflow using pip. The installation always stops(see below). Several minutes later I have to terminate it. Does it cause some packages missing?
Thank you!
Tensorflow 2.7 requires to install keras individually with pip install keras an then you can use keras like before the release: from tensorflow import keras.
I have been trying to retrain Inception by following the tutorial here:
https://www.tensorflow.org/tutorials/image_retraining.
I get this error "No module named backports"
when I run this
bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir ~/marine_animal_species1
This is the full Traceback:
Traceback (most recent call last):
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/examples/image_retraining/retrain.py", line 91, in <module>
import tensorflow as tf
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 64, in <module>
from tensorflow.python.framework.framework_lib import *
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/framework_lib.py", line 100, in <module>
from tensorflow.python.framework.subscribe import subscribe
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/framework/subscribe.py", line 26, in <module>
from tensorflow.python.ops import variables
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/variables.py", line 26, in <module>
from tensorflow.python.ops import control_flow_ops
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/control_flow_ops.py", line 70, in <module>
from tensorflow.python.ops import tensor_array_ops
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/ops/tensor_array_ops.py", line 33, in <module>
from tensorflow.python.util import tf_should_use
File "/home/karthik/tensorflow/bazel-bin/tensorflow/examples/image_retraining/retrain.runfiles/org_tensorflow/tensorflow/python/util/tf_should_use.py", line 28, in <module>
from backports import weakref # pylint: disable=g-bad-import-order
ImportError: No module named backports
I use ubuntu 16.04.
Thank you for the help.
sudo pip install backports.weakref
sudo pip3 install backports.weakref
Solved the problem for me.
Install the weakref module from the backports namespace.
You can get the wheel file from https://pypi.python.org/pypi/backports.weakref/1.0rc1 & install the downloaded wheel as such:
sudo pip install backports.weakref-1.0rc1-py2-none-any.whl # python2
sudo pip3 install backports.weakref-1.0rc1-py3-none-any.whl # python3
Then run your command
bazel-bin/tensorflow/...
This should solve your problem.
I got an error when I wanted to use tensorflow.
I just installed tensorflow and I did
$ source activate tensorflow
command, terminal became tensorflow version like
(tensorflow) ~ master
But I wrote sample.py like
import tensorflow as tf
import multiprocessing as mp
core_num = mp.cpu_count()
config = tf.ConfigProto(
inter_op_parallelism_threads=core_num,
intra_op_parallelism_threads=core_num )
sess = tf.Session(config=config)
hello = tf.constant('hello, tensorflow!')
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
and I run this script like python rote sample.py
so this error happen
Traceback (most recent call last):
File "test.py", line 1, in <module>
import tensorflow as tf
File "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
from tensorflow.python import *
File "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module>
serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
So I searched this error, and I found this solution.
https://github.com/tensorflow/tensorflow/issues/11
I wanna do
pip uninstall protobuf
pip uninstall tensorflow
brew uninstall protobuf
pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl
commands, but only brew uninstall protobuf command could not be done.
So,I did 3 commands and I did python rote sample.py again, but almost same error happen.
Traceback (most recent call last):
File "test.py", line 1, in <module>
import tensorflow as tf
File "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
from tensorflow.python import *
File "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-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 "/Users/username/tensorflow/lib/python2.7/site-packages/tensorflow/core/framework/tensor_shape_pb2.py", line 22, in <module>
serialized_pb=_b('\n,tensorflow/core/framework/tensor_shape.proto\x12\ntensorflow\"d\n\x10TensorShapeProto\x12-\n\x03\x64im\x18\x02 \x03(\x0b\x32 .tensorflow.TensorShapeProto.Dim\x1a!\n\x03\x44im\x12\x0c\n\x04size\x18\x01 \x01(\x03\x12\x0c\n\x04name\x18\x02 \x01(\tb\x06proto3')
TypeError: __init__() got an unexpected keyword argument 'syntax'
What should I do to fix this?
Furthermore,why this error happen?What is wrong?
i just upgraded protobuf to the latest version and it worked for me
pip install protobuf --upgrade
I have default and anaconda python, theano is installed in conda moreover it was also part of anaconda for keras. I am trying to exec a python file from another folder as python ---- and everything is ok except from theano.tensor.fft import ifft where it says no module named theano.tensor.fft I have added PYTHONPATH I have separately added theano in site-package but i can not figure out why it can not import module, please note that I can import theano.tensor I am trying to run MarcBS/keras caffe2keras.py
this is what I got when trying to install theano
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
File "/usr/local/lib/python2.7/dist-packages/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python2.7/dist-packages/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 70, in <module>
ssl.PROTOCOL_SSLv3: OpenSSL.SSL.SSLv3_METHOD,
AttributeError: 'module' object has no attribute 'PROTOCOL_SSLv3'