Qlib 常见问题
Qlib 常见问题解答
1. RuntimeError: 在当前进程完成引导阶段之前尝试启动新进程...
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
这是由于 Windows 操作系统下多进程的限制造成的。有关更多信息,请参阅 这里。
解决方案: 要选择启动方法,您可以在主模块的 if __name__ == '__main__' 子句中使用 D.features。例如:
import qlib
from qlib.data import D
if __name__ == "__main__":
qlib.init()
instruments = ["SH600000"]
fields = ["$close", "$change"]
df = D.features(instruments, fields, start_time='2010-01-01', end_time='2012-12-31')
print(df.head())
2. qlib.data.cache.QlibCacheException: 它发现 redis 锁的 key(...) 现在已存在于您的 redis 数据库中。
它发现 redis 锁的 key 现在已存在于您的 redis 数据库中。您可以使用以下命令清除您的 redis 键并重新运行您的命令
$ redis-cli
> select 1
> flushdb
如果问题未解决,请使用 keys * 查找是否存在多个键。如果是,请尝试使用 flushall 清除所有键。
备注
qlib.config.redis_task_db 的默认值为 1,用户可以使用 qlib.init(redis_task_db=<other_db>) 设置。
此外,欢迎在我们的 GitHub 仓库中发布新问题。我们始终仔细检查每个问题,并尽力解决它们。
3. ModuleNotFoundError: 没有名为 'qlib.data._libs.rolling' 的模块
#### Do not import qlib package in the repository directory in case of importing qlib from . without compiling #####
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "qlib/qlib/__init__.py", line 19, in init
from .data.cache import H
File "qlib/qlib/data/__init__.py", line 8, in <module>
from .data import (
File "qlib/qlib/data/data.py", line 20, in <module>
from .cache import H
File "qlib/qlib/data/cache.py", line 36, in <module>
from .ops import Operators
File "qlib/qlib/data/ops.py", line 19, in <module>
from ._libs.rolling import rolling_slope, rolling_rsquare, rolling_resi
ModuleNotFoundError: No module named 'qlib.data._libs.rolling'
如果在使用
PyCharmIDE 导入qlib包时发生错误,用户可以在项目根文件夹中执行以下命令以编译 Cython 文件并生成可执行文件:python setup.py build_ext --inplace
如果在使用命令
python导入qlib包时发生错误,用户需要更改运行目录,以确保脚本不在项目目录中运行。
4. BadNamespaceError: / 不是一个连接的命名空间
File "qlib_online.py", line 35, in <module>
cal = D.calendar()
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 973, in calendar
return Cal.calendar(start_time, end_time, freq, future=future)
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 798, in calendar
self.conn.send_request(
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\client.py", line 101, in send_request
self.sio.emit(request_type + "_request", request_content)
File "G:\apps\miniconda\envs\qlib\lib\site-packages\python_socketio-5.3.0-py3.8.egg\socketio\client.py", line 369, in emit
raise exceptions.BadNamespaceError(
BadNamespaceError: / is not a connected namespace.
qlib 中的
python-socketio版本需要与 qlib-server 中的python-socketio版本相同:pip install -U python-socketio==<qlib-server python-socketio version>
5. TypeError: send() 收到了一个意外的关键字参数 'binary'
File "qlib_online.py", line 35, in <module>
cal = D.calendar()
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 973, in calendar
return Cal.calendar(start_time, end_time, freq, future=future)
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\data.py", line 798, in calendar
self.conn.send_request(
File "e:\code\python\microsoft\qlib_latest\qlib\qlib\data\client.py", line 101, in send_request
self.sio.emit(request_type + "_request", request_content)
File "G:\apps\miniconda\envs\qlib\lib\site-packages\socketio\client.py", line 263, in emit
self._send_packet(packet.Packet(packet.EVENT, namespace=namespace,
File "G:\apps\miniconda\envs\qlib\lib\site-packages\socketio\client.py", line 339, in _send_packet
self.eio.send(ep, binary=binary)
TypeError: send() got an unexpected keyword argument 'binary'
python-engineio版本需要与python-socketio版本兼容,参考:https://github.com/miguelgrinberg/python-socketio#version-compatibilitypip install -U python-engineio==<compatible python-socketio version> # or pip install -U python-socketio==3.1.2 python-engineio==3.13.2