文档1.0 (latest)
页面可能出现的错误 · 29 / 29

可能出现的错误及解决方法

您在 QuantCraft IDE 中可能遇到的常见错误及其解决方法。随着更多问题被记录,本页会不断扩充。有关软件包安装的一般说明,请参阅依赖项。

错误索引


软件包安装:“a file it ships is in use”

您会看到什么

从 IDE Packages 安装软件包失败,并显示:

Package install failed (polars): Could not install 'polars' — a file it ships is in use (a compiled extension like this is loaded by the editor's background workers, so pip can't replace it). Quit QuantCraft to release the file, reopen it, and install again. Pinning an exact version that is already installed avoids the overwrite.

其底层原因是,pip 在 IDE 的 Python 环境中的某个已编译扩展(如 _polars_runtime.pyd 这样的 .pyd、.so 或 .dll 文件)上,于 Windows 遇到 [WinError 5] Access is denied(macOS / Linux 上为 [Errno 13] Permission denied)。

为什么会发生

某些软件包(polars、numpy、pyarrow 及其他原生库)附带一个在导入软件包时加载到内存中的已编译扩展。IDE 的后台工作进程会导入您已安装的软件包以支持自动补全和分析,这会加载该文件。当前已加载的文件无法被覆盖,所以当 pip 在安装或升级期间尝试替换它时,操作系统会将其阻止。

这就是为什么安装最新版本时可能出现该问题(pip 必须覆盖已加载的文件),而固定一个已安装的版本时不会出现(pip 发现无需更改,会完全跳过该文件)。

如何解决

  1. 完全退出 QuantCraft —— 这会结束占用该文件的后台 Python 工作进程。
  2. 重新打开 QuantCraft。
  3. 再次安装该软件包,最好在打开或运行导入它的脚本之前进行。

提示:

  • 如果软件包已安装并且正常工作,通常根本无需重新安装。
  • 固定一个已安装的确切版本(例如 polars==1.41.2)可避免覆盖,无需重启即可成功。

软件包安装:“pip metadata is missing” / “broken install”

您会看到什么

Could not install 'somepkg' (pip metadata is missing). Try installing again to force a clean copy, or quit QuantCraft, delete the ide-venv folder, and restart the app.

或 Could not install 'somepkg' (broken install).

为什么会发生

之前的某次安装或卸载被中断,使软件包处于半安装状态,因此 pip 找不到记录其拥有哪些文件的信息。

如何解决

  1. 从 IDE Packages 再次安装该软件包 —— 这通常会强制得到一份干净的副本。
  2. 如果仍然失败,请退出 QuantCraft,删除消息中显示的 ide-venv 文件夹,然后重新启动。应用会重新创建环境;之后请重新安装您额外添加的软件包。

回测:“User script must define callable: …”

策略文件缺少必需回调之一 —— on_init、on_bar、on_tick 或 on_finish —— 或者它不是函数。Test 按钮只检查 on_init / on_bar / on_finish,因此缺少 on_tick 是常见原因。如果您不需要它,请添加以下内容:

def on_tick(bar_index, tick_in_bar, price, bar, symbol=None): pass

请参阅策略生命周期。


回测:“No bars in the selected date range after warmup filter …”

您的开始/结束日期范围内没有时钟标的的 K 线 —— 例如仅包含周末的范围、早于该标的开始交易的日期,或超出可用数据的范围。请扩大日期范围或检查标的。QuantCraft(B2)数据源可能改为显示 No AAPL bars (d) between … Available range is … to …,它会告诉您有效范围。请参阅 OHLCV 与 K 线数据。


回测:“A screener symbol source needs an explicit start and end date …”

Symbol source 为 Screener 的回测会在加载任何 K 线之前,根据日期范围确定其再平衡计划,因此两个日期都是必需的。请在 Simulation 标签页上设置 Start 和 End。请参阅选股器。


Debug Test:“Debug test doesn't support a Screener symbol source …”

Debug Test 运行固定的标的列表。请将 Symbol source 切换为 Selected symbols,从您的筛选结果中选一两个股票代码,并使用它们进行调试。请参阅调试。

阅读约 2 分钟建议修改 ↗
可能出现的错误 — 文档 (1.0 (latest)) | QuantCraft