Trying to use C++ implementation of python but api_implementation.Type() still returns 'python' instead of 'cpp'

1,695 views
Skip to first unread message

Oi Lee

unread,
Jul 29, 2016, 1:10:08 PM7/29/16
to Protocol Buffers
I initially used a pure python implementation of protocol buffers, but I changed it later to use the c++ library implementation. So I installed protobuf using these github instructions and then I followed these instructions to use the C++ implementation. But when I use  api_implementation.Type(), it still returns 'python'.  Why is it still using the python implementation?  If this function should not be used, then what should I use to check implementation? 
I'm using protocol buffers 2.6.1 on CentOS. 

Feng Xiao

unread,
Jul 29, 2016, 3:30:39 PM7/29/16
to Oi Lee, Jie Luo, Protocol Buffers
+Jie

On Fri, Jul 29, 2016 at 10:10 AM, Oi Lee <lee...@gmail.com> wrote:
I initially used a pure python implementation of protocol buffers, but I changed it later to use the c++ library implementation. So I installed protobuf using these github instructions and then I followed these instructions to use the C++ implementation. But when I use  api_implementation.Type(), it still returns 'python'.  Why is it still using the python implementation?  If this function should not be used, then what should I use to check implementation? 
I'm using protocol buffers 2.6.1 on CentOS. 

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Jie Luo

unread,
Jul 29, 2016, 5:25:10 PM7/29/16
to Feng Xiao, Oi Lee, Protocol Buffers
 I tried and it returns 'cpp' as expected.

First, make sure you use the correct commands:
python setup.py build --cpp_implementaion
python setup.py install --cpp_implementaion


Second, Where do you put your .py file to check api_implementation.Type()? Make sure your file does not under protobuf/python (DO NOT in the same directory as setup.py)

Oi Lee

unread,
Jul 29, 2016, 6:15:38 PM7/29/16
to Protocol Buffers, xiao...@google.com, lee...@gmail.com
My .py file that checks for implementation is in a completely different folder. I'll try re-installing again.

Oi Lee

unread,
Aug 1, 2016, 3:28:29 PM8/1/16
to Protocol Buffers, xiao...@google.com, lee...@gmail.com
When I do 
[localhost python]$ sudo python setup.py build --cpp_implementaion

Installed [...]/protobuf-2.6.1/python/.eggs/google_apputils-0.4.2-py2.7.egg
Searching for python-gflags>=1.4
Best match: python-gflags 3.0.5
Processing python-gflags-3.0.5.tar.gz
Writing /tmp/easy_install-c_jdOd/python-gflags-3.0.5/setup.cfg
Running python-gflags-3.0.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-c_jdOd/python-gflags-3.0.5/egg-dist-tmp-M2uDeX
zip_safe flag not set; analyzing archive contents...
Moving python_gflags-3.0.5-py2.7.egg to /home/oi.lee/Downloads/protobuf-2.6.1/python/.eggs

Installed [...]/protobuf-2.6.1/python/.eggs/python_gflags-3.0.5-py2.7.egg
Searching for python-dateutil>=1.4
Best match: python-dateutil 2.5.3
Processing python-dateutil-2.5.3.zip
Writing /tmp/easy_install-F99Iys/python-dateutil-2.5.3/setup.cfg
Running python-dateutil-2.5.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-F99Iys/python-dateutil-2.5.3/egg-dist-tmp-YXfHJw
warning: no previously-included files matching '__pycache__' found anywhere in distribution
warning: no previously-included files matching '*.py[co]' found anywhere in distribution
Moving python_dateutil-2.5.3-py2.7.egg to /home/oi.lee/Downloads/protobuf-2.6.1/python/.eggs

Installed [...]/protobuf-2.6.1/python/.eggs/python_dateutil-2.5.3-py2.7.egg
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: option --cpp_implementaion not recognized



On Friday, July 29, 2016 at 3:25:10 PM UTC-6, Jie Luo wrote:

Paul Johnston

unread,
Aug 1, 2016, 7:17:42 PM8/1/16
to Protocol Buffers, xiao...@google.com, lee...@gmail.com
"--cpp_implementaion" misspelled, should be "--cpp_implementation"
Message has been deleted

Oi Lee

unread,
Aug 2, 2016, 12:22:35 PM8/2/16
to Protocol Buffers, xiao...@google.com, lee...@gmail.com
Thanks. That worked. However, when I run my testfile.py I get the following error:
[localhost git]$ python testfile.py 
Traceback (most recent call last):
  File "testfile.py", line 4, in <module>
    import test
  File "[...]/Documents/git/test.py", line 4, in <module>
    import proto.DSMessagesv3_pb2 as msg
  File "[...]/Documents/git/proto/DSMessagesv3_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
  File "/usr/lib/python2.7/site-packages/google/protobuf/descriptor.py", line 50, in <module>
    from google.protobuf.pyext import _message
ImportError: cannot import name _message


From the descriptor.py file here is where it fails:
  if api_implementation.Version() == 2:
    from google.protobuf.pyext import _message
  else:
    from google.protobuf.internal import cpp_message

Also, before I ran my file I export the following environment variables per README file in the python folder.
$ export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
$ export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2


Reply all
Reply to author
Forward
0 new messages