当前环境:

  operate system: Ubuntu 14.04.1 LTS

  protoc --version: libprotoc 2.5.0   

  protocol-buffers version:2.6.1

按照 https://github.com/google/protobuf 的 README.md 流程看的糊涂, 一直在寻找更方便的安装方式。

步骤:

1) 关于pypi: https://pypi.python.org/pypi/protobuf/2.6.1 即可通过 pip install protobuf 方式安装。

验证:

  1. $ python
  2. Python 2.7.6 (default, Jun 22 2015, 17:58:13)
  3. [GCC 4.8.2] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> import google.protobuf
  6. >>>

2) 关于protobuf-compiler:  apt-get install protobuf-compiler

  1. $ apt-get install protobuf-compiler
  2. $
  3. $ protoc --help
  4. Usage: protoc [OPTION] PROTO_FILES
  5. Parse PROTO_FILES and generate output based on the options given:
  6. -IPATH, --proto_path=PATH Specify the directory in which to search for
  7. imports. May be specified multiple times;
  8. directories will be searched in order. If not
  9. given, the current working directory is used.
  10. --version Show version info and exit.
  11. -h, --help Show this text and exit.
  12. --encode=MESSAGE_TYPE Read a text-format message of the given type
  13. from standard input and write it in binary
  14. to standard output. The message type must
  15. be defined in PROTO_FILES or their imports.
  16. --decode=MESSAGE_TYPE Read a binary message of the given type from
  17. standard input and write it in text format
  18. to standard output. The message type must
  19. be defined in PROTO_FILES or their imports.
  20. --decode_raw Read an arbitrary protocol message from
  21. standard input and write the raw tag/value
  22. pairs in text format to standard output. No
  23. PROTO_FILES should be given when using this
  24. flag.
  25. -oFILE, Writes a FileDescriptorSet (a protocol buffer,
  26. --descriptor_set_out=FILE defined in descriptor.proto) containing all of
  27. the input files to FILE.
  28. --include_imports When using --descriptor_set_out, also include
  29. all dependencies of the input files in the
  30. set, so that the set is self-contained.
  31. --include_source_info When using --descriptor_set_out, do not strip
  32. SourceCodeInfo from the FileDescriptorProto.
  33. This results in vastly larger descriptors that
  34. include information about the original
  35. location of each decl in the source file as
  36. well as surrounding comments.
  37. --error_format=FORMAT Set the format in which to print errors.
  38. FORMAT may be 'gcc' (the default) or 'msvs'
  39. (Microsoft Visual Studio format).
  40. --plugin=EXECUTABLE Specifies a plugin executable to use.
  41. Normally, protoc searches the PATH for
  42. plugins, but you may specify additional
  43. executables not in the path using this flag.
  44. Additionally, EXECUTABLE may be of the form
  45. NAME=PATH, in which case the given plugin name
  46. is mapped to the given executable even if
  47. the executable's own name differs.
  48. --cpp_out=OUT_DIR Generate C++ header and source.
  49. --java_out=OUT_DIR Generate Java source file.
  50. --python_out=OUT_DIR Generate Python source file.

详情如下:

  1. $ apt-get install protobuf-compiler
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following extra packages will be installed:
  6. libprotobuf8 libprotoc8
  7. The following NEW packages will be installed:
  8. libprotobuf8 libprotoc8 protobuf-compiler
  9. 0 upgraded, 3 newly installed, 0 to remove and 1 not upgraded.
  10. Need to get 550 kB of archives.
  11. After this operation, 2,133 kB of additional disk space will be used.
  12. Do you want to continue? [Y/n] y
  13. Get:1 http://mirrors.aliyun.com/ubuntu/ trusty/main libprotobuf8 amd64 2.5.0-9ubuntu1 [296 kB]
  14. Get:2 http://mirrors.aliyun.com/ubuntu/ trusty/main libprotoc8 amd64 2.5.0-9ubuntu1 [235 kB]
  15. Get:3 http://mirrors.aliyun.com/ubuntu/ trusty/main protobuf-compiler amd64 2.5.0-9ubuntu1 [19.8 kB]
  16. Fetched 550 kB in 0s (608 kB/s)
  17. Selecting previously unselected package libprotobuf8:amd64.
  18. (Reading database ... 38145 files and directories currently installed.)
  19. Preparing to unpack .../libprotobuf8_2.5.0-9ubuntu1_amd64.deb ...
  20. Unpacking libprotobuf8:amd64 (2.5.0-9ubuntu1) ...
  21. Selecting previously unselected package libprotoc8:amd64.
  22. Preparing to unpack .../libprotoc8_2.5.0-9ubuntu1_amd64.deb ...
  23. Unpacking libprotoc8:amd64 (2.5.0-9ubuntu1) ...
  24. Selecting previously unselected package protobuf-compiler.
  25. Preparing to unpack .../protobuf-compiler_2.5.0-9ubuntu1_amd64.deb ...
  26. Unpacking protobuf-compiler (2.5.0-9ubuntu1) ...
  27. Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
  28. Setting up libprotobuf8:amd64 (2.5.0-9ubuntu1) ...
  29. Setting up libprotoc8:amd64 (2.5.0-9ubuntu1) ...
  30. Setting up protobuf-compiler (2.5.0-9ubuntu1) ...
  31. Processing triggers for libc-bin (2.19-0ubuntu6.6) ...
  32. $
  33. $ protoc // 不报错说明成功

应用:

安装成功后即可按照https://developers.google.com/protocol-buffers/docs/pythontutorial?hl=zh-cn 教程开始使用。

疑问:

关于如何在centos 7/ Mac OS X 操作系统中安装 protobuf-compiler 的简便方法 还未找到方法。再更新吧。

how to install protobuff python的更多相关文章

  1. [Python Debug] How to install external python package? MAC系统下的xgboost安装

    从昨天晚上开始安装xgboost,经历了各种稀奇古怪的错误,终于现在程序可以跑起来了.整个过程对python编译环境,路径设置,package安装方法有了一定了解,当然还有一些疑惑,所以姑且做个记录. ...

  2. install stackless python on ubuntu

    前言 我准备用stackless模拟游戏玩家登陆/注册等行为,测试游戏服务器的性能. 但是在安装stackless的过程中遇到了很多问题,特此记录下来,也分享给需要的朋友. 关于stackless S ...

  3. error: Unable to find vcvarsall.bat while install python library by pip install or python setup.py install.

    Python 2.7 会搜索 Visual Studio 2008. 如果你电脑上没有这个版本的话,比如只有: 1.Visual Studio 2010,在cmd里面执行:SET VS90COMNTO ...

  4. Python package install血泪史

    [前言][絮絮叨叨篇]:说实话,不是第一次安装Python库了,但是貌似没有特别顺利的时候,可能还是遇到的困难不够多咯.配置环境真是个糟心的事儿,不过作为菜鸟,还是得磨练磨练,毕竟某人云:" ...

  5. Install OpenCV 3.0 and Python 2.7+ on OSX

    http://www.pyimagesearch.com/2015/06/15/install-OpenCV-3-0-and-Python-2-7-on-osx/ As I mentioned las ...

  6. Install OpenCV 3.0 and Python 2.7+ on Ubuntu

    为了防止原文消失或者被墙,转载留个底,最好还是去看原贴,因为随着版本变化,原贴是有人维护升级的 http://www.pyimagesearch.com/2015/06/22/install-Open ...

  7. Python 安装第三方库,pip install 安装慢,安装不上的解决办法

    今天来说一下,有些刚刚接触python的朋友,在使用pip install安装python 第三方库的过程中 会出现网速很慢,或者是安装下载到中途,停止,卡主,或者是下载报错等问题.如下图: 还有一些 ...

  8. Python在Linux下编译安装报错:Makefile:1141:install

    正常情况下执行:./configuremake && make install可以直接安装python,但是在在更新了乌版图后居然报错了!!!检查了一圈,发现乌版图安装了python3 ...

  9. Python学习笔记: pip install 常见错误汇总

    本机环境RHEL8, Python3.9 pip install: 无法安装最新版本的包 在pypi上查看pkg的页面,因为有些pip包的版本对特定的python版本有要求 pip install e ...

随机推荐

  1. pycharm问题集锦

    1.pycharm的激活方式 参考博客https://blog.csdn.net/u014044812/article/details/78727496 2.总是出现波浪线,如下问题 问题原因:knn ...

  2. Selenium-webdriver+八种元素定位

    进行Web页面自动化测试,对页面上的元素进行定位和操作是核心.而操作又是以定位为前提的,因此,对页面元素的定位是进行自动化测试的基础. 页面上的元素就像人一样,有各种属性,比如元素名字,元素id,元素 ...

  3. 关于MySQL去除查询结果重复值

    下面先来看看例子: table:  id name  1 a  2 b  3 c  4 c  5 b 库结构大概这样,这只是一个简单的例子,实际情况会复杂得多. 比如我想用一条语句查询得到name不重 ...

  4. 关于Tomcat重启和关闭后重启session变化

    ,当页面第一次访问,session的attribute还未赋值,为null 当页面第二次访问时,这时当前的session的attribute有值了! 到了本文章的点题时刻!! 如果我是直接点击serv ...

  5. RAC+单实例场景下 DG主备切换,报ORA-01577

    SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMAR ...

  6. WPF C# 创建缩略图

    不太精确的方法: public bool ThumbnailCallback() { return false; } private void CreateThumb(int toWidth) { S ...

  7. nw.js node-webkit基本程序结构与配置package.json配置说明

    (一)基本程序结构 如上图,是一个nw程序的基本组织结构,在根目录下有package.json(程序的配置文件)和index.html(可以是任意名称,应用的启动页面):js/css/resource ...

  8. 【Python】—— 获取函数内部变量名称

    原文出处: https://blog.csdn.net/maixiaochai/article/details/88693507 关键语句: func_vars = func.__code__.co_ ...

  9. flask环境布署--废弃不用,只留作备份

    [前置条件] 创建1个flask-demo,生成requirement.txt文件(下载好gunicorn),上传至git.创建demo参照:创建一个flask api-demo(响应体显示中文) g ...

  10. 【漏洞学习】slowHTTPtest 慢速 DOS 攻击方法 修复方案

    日期:2018-05-28 21:41:59 更新:2019-07-05 23:15:21 作者:Bay0net 介绍:学习一下 slowHTTPtest 的攻击及防御. 0x01. 安装 下载链接 ...