712 浏览
0
<span class="ansi-red-intense-fg ansi-bold">Exception</span>: TqSdk 使用了 python3 的原生协程和异步通讯库 asyncio,您所使用的 IDE 不支持 asyncio, 请使用 pycharm 或其它支持 asyncio 的 IDEw

用Jupyter Notebook无法运行怎么处理

qbjstone 已回答的问题 2024年3月6日
0

好像升级到3.5之后的原因,我的原来正常的模块,都不正常了,也是相同的提示,问题是我用的就是pycharm:
PyCharm 2023.3.4 (Professional Edition)
Build #PY-233.14475.56, built on February 26, 2024
Licensed to signup scooter
You have a perpetual fallback license for this version.
Subscription is active until August 1, 2025.
Runtime version: 17.0.10+1-b1087.17 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 8192M
Cores: 16
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
editor.minimap.enabled=true
Non-Bundled Plugins:
wiesmak.rnbwdshpb (1.5)
com.andrey4623.rainbowcsv (2.0.2)
io.github.huacnlee.autocorrect (1.3.1)
com.github.catppuccin.jetbrains (3.2.3)
DBN (3.4.3073.0)
com.intellij.ideolog (222.3.1.0)
CopilotDarkTheme (1.0.4)
indent-rainbow.indent-rainbow (2.2.0)
com.chriscarini.jetbrains.jetbrains-auto-power-saver (3.2.4)
izhangzhihao.rainbow.brackets (2024.2.1)
ca.rightsomegoodgames.mayacharm (3.2.7)
com.intellij.bigdatatools.core (233.14475.28)
com.intellij.bigdatatools.kafka (233.13135.103)
com.intellij.bigdatatools.binary.files (233.11799.267)
com.intellij.bigdatatools.rfs (233.14475.28)
org.custompush (2.0.0)
com.alexandermalcin.browser (1.0.7)
io.kanro.idea.plugin.protobuf (1.7.50)

错误提示一样:

C:\ProgramData\anaconda3\envs\lh166\python.exe -X pycache_prefix=C:\Users\qbjst\AppData\Local\JetBrains\PyCharm2023.3\cpython-cache “C:/Program Files/JetBrains/PyCharm 2023.3.4/plugins/python/helpers/pydev/pydevd.py” –multiprocess –qt-support=auto –client 127.0.0.1 –port 45593 –file H:\code\src\lh15\开始引入API\contract_util.py
Connected to pydev debugger (build 233.14475.56)
在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/
Traceback (most recent call last):
File “C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\api.py”, line 297, in __init__
if not self.wait_update(deadline=deadline): # 等待连接成功并收取截面数据
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\api.py”, line 1878, in wait_update
raise Exception(
Exception: TqSdk 使用了 python3 的原生协程和异步通讯库 asyncio,您所使用的 IDE 不支持 asyncio, 请使用 pycharm 或其它支持 asyncio 的 IDE

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Program Files\JetBrains\PyCharm 2023.3.4\plugins\python\helpers\pydev\pydevd.py”, line 1534, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\JetBrains\PyCharm 2023.3.4\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py”, line 18, in execfile
exec(compile(contents+”\n”, file, ‘exec’), glob, loc)
File “H:\code\src\lh15\开始引入API\contract_util.py”, line 52, in <module>
asyncio.run (main ( ))
File “C:\Program Files\JetBrains\PyCharm 2023.3.4\plugins\python\helpers-pro\pydevd_asyncio\pydevd_nest_asyncio.py”, line 120, in run
return loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Program Files\JetBrains\PyCharm 2023.3.4\plugins\python\helpers-pro\pydevd_asyncio\pydevd_nest_asyncio.py”, line 211, in run_until_complete
return f.result()
^^^^^^^^^^
File “C:\ProgramData\anaconda3\envs\lh166\Lib\asyncio\futures.py”, line 203, in result
raise self._exception.with_traceback(self._exception_tb)
File “C:\ProgramData\anaconda3\envs\lh166\Lib\asyncio\tasks.py”, line 314, in __step_run_and_handle_result
result = coro.send(None)
^^^^^^^^^^^^^^^
File “H:\code\src\lh15\开始引入API\contract_util.py”, line 34, in main
api = TqApi (auth=TqAuth (“132xxxxxxxxx”, “qbjxxxxxxxxxx”))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\api.py”, line 301, in __init__
self.close()
File “C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\api.py”, line 352, in close
raise Exception(
Exception: TqSdk 使用了 python3 的原生协程和异步通讯库 asyncio,您所使用的 IDE 不支持 asyncio, 请使用 pycharm 或其它支持 asyncio 的 IDE
Task was destroyed but it is pending!
task: <Task pending name=’Task-7′ coro=<TqTradingStatus._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\trading_status.py:16> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-8′ coro=<BaseSim._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\tradeable\sim\basesim.py:61> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-10′ coro=<DataExtension._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\data_extension.py:74> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-9′ coro=<TqWebHelper._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\tqwebhelper.py:74> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-5′ coro=<TqReconnect._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\connect.py:270> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-6′ coro=<TqSymbols._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\symbols.py:15> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-2′ coro=<TqBaseApi._windows_patch() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\baseApi.py:116> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-4′ coro=<TqConnect._run() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\connect.py:110> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-3′ coro=<TqApi._notify_watcher() running at C:\Users\qbjst\AppData\Roaming\Python\Python312\site-packages\tqsdk\api.py:3634> cb=[TqBaseApi._on_task_done()]>
sys:1: RuntimeWarning: coroutine ‘TqTradingStatus._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘BaseSim._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘DataExtension._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqWebHelper._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqReconnect._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqSymbols._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqBaseApi._windows_patch’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqConnect._run’ was never awaited
sys:1: RuntimeWarning: coroutine ‘TqApi._notify_watcher’ was never awaited

Process finished with exit code 1

附原来正常的模块:

#!/user/bin/env python3
# -*- coding: utf-8 -*-

# 引入模块
from tqsdk import TqApi, TqAuth, TqSim

def get_my_major_contracts(api):
    exchanges = ["CFFEX", "SHFE", "CZCE", "DCE", "INE", "GFEX"]  # 交易所列表
    products = ["rb", "cu", "jm", "OI", "MA", "SA", "p", "RM", "FG", "y", "m", "b", "j", "sp", "pg", "fu", "bu", "TA",
                "eb", "ss", "eg", "sc", "zn", "ni", "pb", "PF", "pp", "al", "IH", "ag", "IF", "v", "lu", "IC", "bc",
                "ao", "TL", "IM", "rr", "l", "i", "a", "c", "T", "TF", "SF", "SM", "UR", "PK", "CJ", "jd", "lh", "AP",
                "TS", "hc", "au", "CY", "CF", "cs", "nr", "ru", "SR", "sn", "br", "si", "lc", "ec",
                "SH"]  # 期货品种列表,根据实际需求添加或修改

    major_contracts = []  # 主力合约列表

    for exchange in exchanges:
       for product in products:
          symbols = api.query_quotes (ins_class="FUTURE", exchange_id=exchange, product_id=product, expired=False)
          quote_list = api.get_quote_list (symbols)

          if len (quote_list) > 0:
             major_contract = max (quote_list, key=lambda q: q.open_interest)
             major_contracts.append (major_contract.instrument_id)

    return major_contracts

# 对这个函数进行测试
if __name__ == '__main__':
    # Create TqApi and TqSim objects for testing
    acc = TqSim ( )
    api = TqApi (acc, auth=TqAuth ("132xxxxxxxx", "qbjxxxxxxxx"))
    symbols = get_my_major_contracts (api)

    print (symbols)
    print ("进入 K 线引用")
    klines = {
       "15min": {symbol: api.get_kline_serial (symbol, 60 * 15) for symbol in symbols},
       "1hour": {symbol: api.get_kline_serial (symbol, 60 * 60) for symbol in symbols},
       "daily": {symbol: api.get_kline_serial (symbol, 24 * 60 * 60) for symbol in symbols},
       "weekly": {symbol: api.get_kline_serial (symbol, 7 * 24 * 60 * 60) for symbol in symbols}
    }

    print ("进入行情引用")
    print (klines)
    api.close ( )

这个模块原来一直正常,就是最近升级之后就不正常了

qbjstone 编辑答案 2024年3月6日
您正在查看2个答案中的1个,单击此处查看所有答案。