【问题标题】:Getting Error :/usr/bin/python: No module named thrift_compiler出现错误:/usr/bin/python:没有名为 thrift_compiler 的模块
【发布时间】:2018-06-12 07:18:11
【问题描述】:

我正在尝试在 ubuntu 16.04 中使用 cpp 运行一个简单的 thrift 通信。我的 thrift 文件夹位于 usr/local/ 中,而我的 thrift.pc 文件位于 usr/local/lib/pkgconfig.my python 文件夹中 2.7 和3.5 版本位于 usr/local/lib 文件夹中。 我正在关注此站点以创建简单的客户端服务器通信 http://www.avabodh.com/thrift/client_server.html

所以我写了一个简单的calculator.thrift 文件 代码

namspace cpp example
service Calculator
{
    i64 add(1:i32 num1, 2:i32 num2);
}

在我的主文件夹中运行

python -m thrift_compiler.main --gen cpp2 calculator.thrift

当我要生成包含所有生成的 cpp 文件的 gen-cpp2 文件夹时出现此错误

/usr/bin/python: No module named thrift_compiler

我的 Thrift 服务器版本是 0.9.3。我对节俭协议很陌生。请帮我弄清楚。谢谢

【问题讨论】:

    标签: python-3.x python-2.7 ubuntu-16.04 thrift


    【解决方案1】:

    IIRC 基于 python 的编译器不久前已从源代码中删除。 Here's 官方 Python 教程,它也应该适用于相当旧的 0.9.3 版本

    简而言之,您需要 make install Thrift 编译器,然后按照教程中的说明运行它以从 IDL 生成代码:

    thrift  --gen cpp  calculator.thrift
    

    要获取有关 cmdline 参数类型的更多信息

    thrift  --help
    

    【讨论】:

      猜你喜欢
      • 2016-01-06
      • 2020-06-13
      • 2021-11-09
      • 2021-01-11
      • 2016-01-17
      • 2018-11-23
      • 2016-03-06
      • 2016-11-03
      • 2023-03-03
      相关资源
      最近更新 更多