#911·rqalpha

scheduler定时器在主目录下一级目录中无法正常import

Author: zhangshougCreated Jan 15, 2025Updated Jan 15, 2025
Labelsbug

提 ISSUE 须知

请先阅读文档 rqalpha文档

如果仍有问题的话请在 issue列表 中寻找是否有相关问题的解决方案

如果没有的话 麻烦开一个issue 描述以下问题:

1. RQAlpha的版本

5.5.0

2. Python的版本

Python 3.10.9

3. 是Windows/Linux/MacOS or others?

Linux

4. 您出现问题对应的源码/或者能复现问题的简易代码 以及对应的配置

(base) zhangshoug@devuan:~$ cat test_scheduler.py from rqalpha.api import scheduler

def init(context): # 安排每月任务 scheduler.run_monthly(my_monthly_task, tradingday=1) # 每月的第 1 个交易日执行

def my_monthly_task(context, bar_dict): # 每月任务的逻辑 print("执行每月任务")

def handle_bar(context, bar_dict): # 处理每个 bar 的逻辑 pass

5. 您出现的错误堆栈日志信息

(base) zhangshoug@devuan:$ cd month/ (base) zhangshoug@devuan:/month$ rqalpha run -f test_scheduler.py -s 2024-07-30 -e 2024-08-02 [2025-01-15 08:07:06.000230] WARN: system_log: PLOT: Missing Chinese fonts. Fallback to English. [2024-07-30 00:00:00.000000] ERROR: user_system_log: 策略运行产生异常 Traceback (most recent call last): File "/opt/anaconda3/lib/python3.10/site-packages/rqalpha/utils/strategy_loader_help.py", line 25, in compile_strategy six.exec_(code, scope) File "test_scheduler.py", line 1, in from rqalpha.api import scheduler ImportError: cannot import name 'scheduler' from 'rqalpha.api' (/opt/anaconda3/lib/python3.10/site-packages/rqalpha/api.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/anaconda3/lib/python3.10/site-packages/rqalpha/main.py", line 185, in run scope = env.strategy_loader.load(scope) File "/opt/anaconda3/lib/python3.10/site-packages/rqalpha/core/strategy_loader.py", line 31, in load return compile_strategy(source_code, self._strategy_file_path, scope) File "/opt/anaconda3/lib/python3.10/site-packages/rqalpha/utils/strategy_loader_help.py", line 52, in compile_strategy raise CustomException(error) rqalpha.utils.exception.CustomException: Traceback (most recent call last): File test_scheduler.py, line 1 in from rqalpha.api import scheduler

ImportError: cannot import name 'scheduler' from 'rqalpha.api' (/opt/anaconda3/lib/python3.10/site-packages/rqalpha/api.py) [2024-07-30 00:00:00.000000] ERROR: user_system_log: Traceback (most recent call last): File test_scheduler.py, line 1 in from rqalpha.api import scheduler

ImportError: cannot import name 'scheduler' from 'rqalpha.api' (/opt/anaconda3/lib/python3.10/site-packages/rqalpha/api.py) (base) zhangshoug@devuan:/month$ cd (base) zhangshoug@devuan:$ rqalpha run -f test_scheduler.py -s 2024-07-30 -e 2024-08-02 [2025-01-15 08:07:20.227273] WARN: system_log: PLOT: Missing Chinese fonts. Fallback to English. [2024-08-01 15:00:00.000000] INFO: user_log: 执行每月任务 /opt/anaconda3/lib/python3.10/site-packages/rqrisk/risk.py:51: RuntimeWarning: invalid value encountered in expm1 return np.expm1(np.log1p(self._benchmark).sum()) /opt/anaconda3/lib/python3.10/site-packages/rqrisk/risk.py:232: RuntimeWarning: invalid value encountered in expm1 return np.expm1(-stats.norm(mean, std).ppf(alpha)) /opt/anaconda3/lib/python3.10/site-packages/rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:467: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning. weekly_b_returns = pandas.Series(index=weekly_returns.index) /opt/anaconda3/lib/python3.10/site-packages/rqalpha/mod/rqalpha_mod_sys_analyser/mod.py:468: FutureWarning: The default dtype for empty Series will be 'object' instead of 'float64' in a future version. Specify a dtype explicitly to silence this warning. monthly_b_returns = pandas.Series(index=monthly_returns.index)