I wanted to use the wonderful package caffe-tensorflow by ethereon and I ran into the same problem described in this closed issue:
When I run the example or try to import caffepb
I got the error message:
>>> import caffepb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "caffepb.py", line 28, in <module>
type=None),
File "/home/me/anaconda/python2.7/site-packages/google/protobuf/descriptor.py", line 652, in __new__
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.
I am using Tensorflow 0.7.0 on a linux 64 bits UBUNTU 14.04 machine with protobuf 3.0.0b2.post (but it also happened with 3.0.0a4 and 3.0.0b2) with Python 2.7 and anaconda.
I tried to reinstall protobuf and tensorflow numerous times as I figured it was quite possibly a conflict between different protobuf installs (or at least that was the conclusion of the github issue) but I couldn't make it work even after doing a combination of pip install protobuf, pip uninstall protobuf or directly installing protobuf .whl.
What would you advise ?
EDIT: Using a virtual environment may be a solution but I would like to avoid it if possible
Renaming any file creating descriptors to have suffix "_pb2.py" will solve this problem.
UPDATE(April 4, 2017): In the "caffe-tensorflow" project, I renamed the "kaffe/caffe/caffepb.py" to "caffe_pb2.py", and this solved the problem. This is the only file I found in this project that creates PB descriptors.
Kai Yu's solution also worked for me. However, I also recommend deleting the "caffepb.pyc" file in caffe-tensorflow/kaffe/caffe to ensure that none of the code can still be using the caffe_pb2 module with the old name.
I believe that this module is only used in the file caffe-tensorflow/kaffe/caffe/resolver.py.
I met the same problem too. My solution (workaround) was the same as one of the comments in the issue - install/run tf and protobuf3 (and anything) in virtualenv.
I have no more idea about what the problem exactly is. This is just one workaround that you can give a try.