【protobuf】protobuf Mac python3

来源:互联网 发布:vb与台达plc通讯 编辑:程序博客网 时间:2024/06/05 19:28

这次尝试安装3.0.0的protobuf在Mac下。

protobuf在3.0以后的版本的安装和2.x有很多区别,而网上大多数还是2.x的方法,这点需要注意,之前也是踩坑了。。。

先下个3.0的:https://github.com/google/protobuf/releases/tag/v3.0.0

然后解压,在src下面找到readme,就是安装核心protobuf的步骤,可以看到,3.0版本需要以下工具:

To build protobuf from source, the following tools are needed:  * autoconf  * automake  * libtool  * curl (used to download gmock)  * make  * g++  * unzip

在ubuntu下很好安,在mac下需要注意下,在这个文档里有mac的步骤。

**Note for Mac users**  For a Mac system, Unix tools are not available by default. You will first need  to install Xcode from the Mac AppStore and then run the following command from  a terminal:    $ sudo xcode-select --install  To install Unix tools, you can install "port" following the instructions at  https://www.macports.org . This will reside in /opt/local/bin/port for most  Mac installations.    $ sudo /opt/local/bin/port install autoconf automake libtool  Then follow the Unix instructions above.

先要安装xcode开发者工具,但是目前好像上述方法不行,直接在appstore里下一个xcode即可。然后命令行:


说明有了。

之后需要用port工具安装之前的那一个列表,安port需要在https://guide.macports.org/下一个pkg包,双击即可。在运行

    $ sudo /opt/local/bin/port install autoconf automake libtool
即可。
然后执行:

    $ ./configure    $ make    $ make check    $ sudo make install    $ sudo ldconfig # refresh shared library cache.
可以在./configure里指定位置,--prefix=path,在再~/.bash_profile里面加环境变量。最后source,具体和另一篇博文一样。这里不说了。

验证:


成功。接下来安装python的支持库。

进入python目录,也有一个readme,打开:大致说了三步骤:

     $ python setup.py build     $ python setup.py test     $ python setup.py install

当然还有其他的,但是我没管。第一步卡住了,直接退出运行后两部,成功了。


验证:


成功。

现在我的电脑上安装了两个python和两个protobuf,使用~/.bash_profile切换即可。

之前没有安装3.x成功的原因我觉得是没有把之前用port安装的那一堆软件安上,这也是和protobuf2.x的区别。

原创粉丝点击