zoukankan      html  css  js  c++  java
  • python 版本 jaeger-client 导入失败 jaeger-client-python

    环境为:

    OS: ubuntu18.04

    Python: 3.6

    问题原因:

    尝试使用 jaeger-client-python,官方给出的示例(https://github.com/jaegertracing/jaeger-client-python ReadMe文件中所述),出现了下面错误

    Traceback (most recent call last):
      File "jaeger.py", line 3, in <module>
        from jaeger_client import Config
      File "/usr/local/lib/python3.6/dist-packages/jaeger_client/__init__.py", line 27, in <module>
        from .config import Config  # noqa
      File "/usr/local/lib/python3.6/dist-packages/jaeger_client/config.py", line 26, in <module>
        from .reporter import (
      File "/usr/local/lib/python3.6/dist-packages/jaeger_client/reporter.py", line 32, in <module>
        from jaeger_client.thrift_gen.agent import Agent
      File "/usr/local/lib/python3.6/dist-packages/jaeger_client/thrift_gen/agent/Agent.py", line 13, in <module>
        from .ttypes import *
      File "/usr/local/lib/python3.6/dist-packages/jaeger_client/thrift_gen/agent/ttypes.py", line 12, in <module>
        import jaeger.ttypes
      File "/mnt/d/code/doc2/13_jaeger/jaeger.py", line 3, in <module>
        from jaeger_client import Config
    ImportError: cannot import name 'Config'  

    经过查找发现是在 thrift 生成的文件中导入包出错

    解决方案:重新打包 .whl 安装包

    step1:下载 jaeger-client-python 源码

    step2:修改代码如下

    文件1:./jaeger_client/thrift_gen/agent/ttypes.py 中,找到

    import jaeger.ttypes
    

    修改为:

    from jaeger_client.thrift_gen.jaeger import ttypes as jaeger_ttypes

    文件2:./jaeger_client/thrift_gen/agent/Agent.py 中,找到

    ...
      thrift_spec = (
        None, # 0
        (1, TType.STRUCT, 'batch', (jaeger.ttypes.Batch, jaeger.ttypes.Batch.thrift_spec), None, ), # 1
      )
    ...
    
          if fid == 1:
            if ftype == TType.STRUCT:
              self.batch = jaeger.ttypes.Batch()
              self.batch.read(iprot)
            else:
    ...
    

    修改其中的 jaeger.ttypes 为 jaeger_ttypes

    step3:在代码根目录下执行编译 

    python3 setup.py sdist bdist_wheel

    完成后,生成的文件在 ./dist 下面,有 .whl 和 tgz 两种格式

  • 相关阅读:
    python 基础2.5 循环中continue与breake用法
    python 基础 2.4 while 循环
    python 基础 2.3 for 循环
    python 基础 2.2 if流程控制(二)
    python 基础 2.1 if 流程控制(一)
    python 基础 1.6 python 帮助信息及数据类型间相互转换
    python 基础 1.5 python数据类型(四)--字典常用方法示例
    Tornado Web 框架
    LinkCode 第k个排列
    LeetCode 46. Permutations
  • 原文地址:https://www.cnblogs.com/newguy/p/11804998.html
Copyright © 2011-2022 走看看