Closed ccliuyang closed 4 years ago
不好意思,没明白“在rqalpha_mod_rqfactor代码中找不到rqfactor模块”是什么意思,麻烦详细描述或附上测试代码。
其出错信息是这样的:
[2020-06-20 17:15:01.293154] ERROR: user_system_log: 策略运行产生异常
Traceback (most recent call last):
File "D:\Miniconda3\lib\site-packages\rqalpha\main.py", line 140, in run
mod_handler.set_env(env)
File "D:\Miniconda3\lib\site-packages\rqalpha\mod\__init__.py", line 56, in set_env
mod = mod_module.load_mod()
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\__init__.py", line 8, in load_mod
from .mod import RQFactorMod
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\mod.py", line 23, in <module>
from .indicator_board import BTIndicatorBoard, PTIndicatorBoard
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\indicator_board.py", line 26, in <module>
from rqfactor.interface import AbstractFactor, UserDefinedLeafFactor
ModuleNotFoundError: No module named 'rqfactor.interface'; 'rqfactor' is not a package
[2020-06-20 17:15:01.294154] ERROR: system_log: 策略运行产生异常
Traceback (most recent call last):
File "D:\Miniconda3\lib\site-packages\rqalpha\main.py", line 140, in run
mod_handler.set_env(env)
File "D:\Miniconda3\lib\site-packages\rqalpha\mod\__init__.py", line 56, in set_env
mod = mod_module.load_mod()
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\__init__.py", line 8, in load_mod
from .mod import RQFactorMod
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\mod.py", line 23, in <module>
from .indicator_board import BTIndicatorBoard, PTIndicatorBoard
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\indicator_board.py", line 26, in <module>
from rqfactor.interface import AbstractFactor, UserDefinedLeafFactor
ModuleNotFoundError: No module named 'rqfactor.interface'; 'rqfactor' is not a package
[2020-06-20 17:15:01.298156] ERROR: system_log: tear down fail for rqfactor
Traceback (most recent call last):
File "D:\Miniconda3\lib\site-packages\rqalpha\main.py", line 140, in run
mod_handler.set_env(env)
File "D:\Miniconda3\lib\site-packages\rqalpha\mod\__init__.py", line 56, in set_env
mod = mod_module.load_mod()
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\__init__.py", line 8, in load_mod
from .mod import RQFactorMod
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\mod.py", line 23, in <module>
from .indicator_board import BTIndicatorBoard, PTIndicatorBoard
File "D:\Miniconda3\lib\site-packages\rqalpha_mod_rqfactor\indicator_board.py", line 26, in <module>
from rqfactor.interface import AbstractFactor, UserDefinedLeafFactor
ModuleNotFoundError: No module named 'rqfactor.interface'; 'rqfactor' is not a package
发生的原因是直接执行 python xxx.py 如果是rqalpha-plus run -f xxx.py 则不会报此错误。 然后我调试之后原因是rqalpha_mod_rqfactor 和rqfactor包重名了。
如果将python下的rqfactor包改为rqfactor2,然后在扩展的mod rqalpha_mod_rqfactor中调用rqfactor2包,则无问题。无论是采用rqalpha-plus run -f xxx.py 还是python xxx.py
奇怪,我又试了下,不是这个命名的问题,改成别的,不会出现这个问题。
终于知道到底是什么原因了,原来是我在我策略的目录下有一个rqfactor.py的策略文件,然后策略在执行的时候,找rqfactor这个包找的是这个文件,不怪说出错误!
1 环境
rqalpha 4.1.3 python 3.7.4 windows
2 问题
rqalpha支持mod方式扩展,但是在mod命名上有个小问题,有一个这样的模块rqalpha_mod_rqfactor, 和rqfactor包,如果我采用rqalpha run -f xxx.py 方式运行,则在rqalpha_mod_rqfactor包中能够找到rqfactor 模块,如果我用python xxx.py方式运行,则在rqalpha_mod_rqfactor代码中找不到rqfactor模块,但是如果我把rqfactor包名称改为rqfactor2,则在rqalpha_mod_rqfactor中能够找到rqfactor2。所以在rqalpha mod包命令的时候,后边的部分不能与已有的包名重复,这样会导致采用python xx.py 方式运行的时候,找不到这个包。这个可能是rqalpha处理mod的时候,没处理好?或者是怎么回事?