Не удается импортировать shared.SharedService в руководство по бережливости

Кажется, я что-то неправильно понимаю в Apache Thrift. Я установил и сгенерировал привязки Python, используя файл tutorial.thrift. Я манипулировал своей переменной окружения PYTHONPATH, чтобы разрешить импорт из сгенерированных файлов. Когда я импортирую tutorial.Calculator' it can't findshared.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
>>> 

person Eric Urban    schedule 19.02.2014    source источник


Ответы (1)


SharedService является частью другого IDL-файла Thrift, который включен в IDL-файл tutorial.thrift. Tbus, вы также должны сгенерировать код для службы Shared. Самый простой способ — вызвать компилятор Thrift с параметром -r («рекурсивный»), который сгенерирует код для переданного IDL-файла и всех включенных зависимостей.

Учебные страницы здесь действительно вводят в заблуждение. Если вы хотите подать заявку JIRA, сделайте это.

person JensG    schedule 19.02.2014
comment
Благодарю за разъяснение. - person Eric Urban; 19.02.2014