这曾经是可能的(请参阅这篇文章:How get BQL (bLOOMBERG) query from python)但是我现在无法让它工作。复制大量包/文件后,我陷入了以下 AttributeError:“zmq.eventloop' 没有属性 'ioloop'”,如果我读到,这是因为我试图在沙盒终端版本之外进行访问。有人找到了在 python 本地使用 BQL 的方法吗?谢谢 - 下面完整的回溯:
AttributeError Traceback (most recent
call last)
Cell In[4], line 4
1 import pandas as pd
2 import bql
----> 4 bq = bql.Service()
5 query = """get(px_last)for('AAPL US EQUITY')with(dates=range(-1y,0d),fill='prev')"""
6 data = bql.combined_df(bq.execute(query)).reset_index()
File c:\Users\user\OneDrive\python311\Lib\site-packages\bql\service.py:306, in Service.__init__(self, metadata_reader, request_executor, preferences, query_parser)
295 """Construct a new Service object.
296
297 Specify `preferences` if you want certain preferences applied to each
(...)
302 precedence over the global preferences specified here.
303 """
304 self.__bqapi_session = None
305 self.__metadata_reader = (metadata_reader or
--> 306 self.__create_metadata_reader())
307 self._request_executor = (request_executor or
308 self.__create_request_executor())
309 self._query_parser = query_parser or self.__create_query_parser()
File c:\Users\user\OneDrive\python311\Lib\site-packages\bql\service.py:324, in Service.__create_metadata_reader(self)
322 def __create_metadata_reader(self):
323 factory = MetadataReaderFactory()
--> 324 return factory.create_metadata_reader()
File c:\Users\user\OneDrive\python311\Lib\site-packages\bqlmetadata\metadata_reader_factory.py:63, in MetadataReaderFactory.create_metadata_reader(self)
60 def create_metadata_reader(self):
61 import bqapi
---> 63 bqapi_session = bqapi.get_session_singleton()
65 bqhopper_breg_value = _get_bqhopper_enablement()
67 if bqhopper_breg_value == 0:
68 # BREG value of 0 will use the legacy, local SQLite
69 # metadata solution or shipped metadata.
File c:\Users\user\OneDrive\python311\Lib\site-packages\bqapi\session_singleton.py:73, in get_session_singleton(settings)
70 # see if we already have a blp api session created for this cache key
71 if key not in _instances:
72 # create a new blp api session, store it in the cache with key
---> 73 _instances[key] = Session(**(settings or {}))
75 return _instances[key]
File c:\Users\user\OneDrive\python311\Lib\site-packages\bqapi\session.py:93, in Session.__init__(self, event_loop, **settings)
68 def __init__(self, event_loop=None, **settings):
69 """Constructor for :class:`Session` instances.
70
71 After constructing a Session object, the session is automatically started
(...)
91 Session settings. See the :class:`Settings` class for more details.
92 """
---> 93 self.event_loop = event_loop or get_default_event_loop()
95 self._settings = Settings(**settings)
96 self._logger = logging.getLogger('bqapi.Session')
File c:\Users\user\OneDrive\python311\Lib\site-packages\bqapi\event_loop.py:518, in get_default_event_loop()
516 global _default_loop
517 if not _default_loop:
--> 518 _ipython_loop = _get_ipython_event_loop()
519 if _ipython_loop:
520 _default_loop = EventLoop(
521 external_loop=TornadoEventLoop(_ipython_loop))
File c:\Users\user\OneDrive\python311\Lib\site-packages\bqapi\event_loop.py:499, in _get_ipython_event_loop()
492 return None
494 # Not needed, we are running a ZMQ kernel now...
495 # kernel = ipython.kernel
496 # if not isinstance(kernel, IPython.kernel.zmq.ipkernel.IPythonKernel):
497 # return None
--> 499 return zmq.eventloop.ioloop.IOLoop.instance()
500 except WindowsError:
501 # Happens when we are in a sandbox and not allowed to load the ZMQ
502 # native DLL. Treat it like an import error; if ZMQ was supposed to
503 # be allowed in the sandbox, it should have been imported before
504 # lowering the token.
505 return None
AttributeError: module 'zmq.eventloop' has no attribute 'ioloop'`
猜测可能与 Spyder 从 zmq 16.0.0 升级有关? 看起来像: 模块:zmq.eventloop.ioloop 该模块在 pyzmq 17 中已弃用。使用tornado.ioloop。 https://pyzmq.readthedocs.io/en/v26.2.0/api/zmq.eventloop.ioloop.html