python - 无法在thrift教程中导入shared.SharedService

标签 python thrift

我似乎误解了 Apache Thrift 的一些内容。我已经安装了它并使用tutorial.thrift 文件生成了python 绑定(bind)。我操纵了 PYTHONPATH 环境变量,以允许我从生成的文件中导入。当我导入tutorial.Calculator'时,它找不到shared.SharedService`。这是 Apache Thrift 的依赖项还是我必须定义的东西?

ericu@eric-phenom-linux:~/tmp$ export PYTHONPATH=$PYTHON:`pwd`/gen-py
ericu@eric-phenom-linux:~/tmp$ echo $PYTHONPATH
:/home/ericu/tmp/gen-py
ericu@eric-phenom-linux:~/tmp$ c
c: command not found
ericu@eric-phenom-linux:~/tmp$ cd 
ericu@eric-phenom-linux:~$ pyhon
No command 'pyhon' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
pyhon: command not found
ericu@eric-phenom-linux:~$ python
Python 2.7.5 Stackless 3.1b3 060516 (default, Sep 23 2013, 20:17:03) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tutorial
>>> tutorial.Calculator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Calculator'
>>> import tutorial.Calculator
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ericu/tmp/gen-py/tutorial/Calculator.py", line 10, in <module>
    import shared.SharedService
ImportError: No module named shared.SharedService
>>> 

最佳答案

SharedService 是另一个 Thrift IDL 文件的一部分,该文件包含在tutorial.thrift IDL 文件中。 Tbus,您还必须生成共享服务的代码。最简单的方法是使用 -r 选项(“递归”)调用 Thrift 编译器,该编译器将为传递的 IDL 文件和所有包含的依赖项生成代码。

这里的教程页面确实具有误导性。如果您想提交 JIRA 票证,请这样做。

关于python - 无法在thrift教程中导入shared.SharedService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21871100/

相关文章:

节省消息中的大文件

python - 使用 Pyrsvg 和 Cairo 在 Python 中渲染 SVG 时出现问题

java - Thrift TServer 服务不返回主线程

python - 在 Python 中复制迭代器

python - 在 64 位 Linux 的 wine 中安装 32bit-python-3.4

Apache Thrift 教程中的 C++ 链接器错误 - undefined symbol

java - 如何在使用 Thrift 文件生成 Bazel 构建时添加依赖项 java 文件

c# - 在 Windows 中运行不同的 makefile

python - 获取“"NameError: name ' IP'未定义”错误消息

python - 值错误 : readline of closed file in Python