FutunnOpen / py-futu-api

富途 OpenAPI Python SDK
Apache License 2.0
1.04k stars 221 forks source link

import futu-api failed with protobuf@3.5.1 #101

Closed Atuna closed 3 years ago

Atuna commented 3 years ago

系统环境:macOS 安装方式: pip install futu-api 版本: Ver.5.9.2108 日志:

% python3 subscribe.py 
Traceback (most recent call last):
  File "/Users/shu/workspace/futu/subscribe.py", line 2, in <module>
    from futu import *
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/futu/__init__.py", line 100, in <module>
    from futu.quote.open_quote_context import OpenQuoteContext
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/futu/quote/open_quote_context.py", line 10, in <module>
    from futu.common.open_context_base import OpenContextBase, ContextStatus
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/futu/common/open_context_base.py", line 11, in <module>
    from futu.common.utils import *
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/futu/common/utils.py", line 6, in <module>
    from google.protobuf.json_format import MessageToJson
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/json_format.py", line 58, in <module>
    from google.protobuf import symbol_database
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/symbol_database.py", line 62, in <module>
    from google.protobuf import message_factory
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/message_factory.py", line 44, in <module>
    from google.protobuf import reflection
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/reflection.py", line 58, in <module>
    from google.protobuf.internal import python_message as message_impl
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/internal/python_message.py", line 62, in <module>
    from google.protobuf.internal import containers
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google/protobuf/internal/containers.py", line 182, in <module>
    MutableMapping = collections.MutableMapping
AttributeError: module 'collections' has no attribute 'MutableMapping'

但当我升级protobuf到3.19.0时,这个问题就可以解决,但在这个commit里有提到说“目前群反馈高版本可能会出问题”,不确定具体指什么问题?

loadatom commented 3 years ago

这是Python3.10的一个变更导致的: `d:\tmp\python-3.8.10-embed-amd64>python Python 3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32

import collections print(collections.MutableMapping)

:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working `

这只能降低Python版本,或者像你做的升级protobuf版本。高版本的protobuf没有测试过,但只要兼容低版本应该是可以用的。

loadatom commented 3 years ago

计划近期解决这个问题。