Magic安装Mojo依赖lightbug_http失败,运行报错求助
无法在Mojo项目中使用lightbug_http依赖的问题
操作流程
- 初始化项目并验证基础功能:
magic init hello_web --format mojoproject cd hello_web magic shell
此时打印Hello world功能正常。
- 添加依赖渠道并安装包:
将https://repo.prefix.dev/mojo-community添加到mojoproject.toml的渠道列表,执行:
magic add lightbug_http magic install
- 修改
src/main.mojo代码:
from lightbug_http import Welcome, Server fn main() raises: print ("Hello world") var server = Server() var handler = Welcome() server.listen_and_serve("0.0.0.0:8080", handler)
报错信息
运行mojo run src/main.mojo时触发以下错误:
hello_web/.magic/envs/default/lib/mojo/small_time.mojopkg:0:0: error: expected mlir::TypedAttr, but got: @stdlib hello_web/.magic/envs/default/lib/mojo/small_time.mojopkg:0:0: note: in bytecode version 6 produced by: MLIR20.0.0git hello_web/src/main.mojo:1:1: error: unable to load package 'hello_web/.magic/envs/default/lib/mojo/small_time.mojopkg' from lightbug_http import Welcome, Server ^ mojo: error: failed to parse the provided Mojo source module
权限差异观察
新安装的包与初始项目自带包存在权限差异:
(hello_web) ➜ hello_web ls -l .magic/envs/default/lib/mojo total 45268 -rwxr-xr-x 1 thomas thomas 1971956 31 déc. 12:01 algorithm.mojopkg -rwxr-xr-x 1 thomas thomas 715410 31 déc. 12:01 autotune.mojopkg -rwxr-xr-x 1 thomas thomas 1433315 31 déc. 12:01 benchmark.mojopkg -rwxr-xr-x 1 thomas thomas 1094280 31 déc. 12:01 buffer.mojopkg -rwxr-xr-x 1 thomas thomas 788720 31 déc. 12:01 compile.mojopkg -rwxr-xr-x 1 thomas thomas 707945 31 déc. 12:01 compiler_internal.mojopkg -rwxr-xr-x 1 thomas thomas 1705 31 déc. 12:01 compiler.mojopkg -rwxr-xr-x 1 thomas thomas 714424 31 déc. 12:01 complex.mojopkg -rwxr-xr-x 1 thomas thomas 9930965 31 déc. 12:01 gpu.mojopkg -rwxr-xr-x 1 thomas thomas 974993 31 déc. 12:01 kv_cache.mojopkg -rwxr-xr-x 1 thomas thomas 3348271 31 déc. 12:01 layout.mojopkg -rw-r--r-- 1 thomas thomas 2109465 31 déc. 12:04 lightbug_http.mojopkg -rwxr-xr-x 1 thomas thomas 7079591 31 déc. 12:01 max.mojopkg -rwxr-xr-x 1 thomas thomas 2515744 31 déc. 12:01 _mlir.mojopkg -rwxr-xr-x 1 thomas thomas 1036088 31 déc. 12:01 runtime.mojopkg -rw-r--r-- 1 thomas thomas 823950 31 déc. 12:04 small_time.mojopkg -rwxr-xr-x 1 thomas thomas 7338653 31 déc. 12:01 stdlib.mojopkg -rwxr-xr-x 1 thomas thomas 757942 31 déc. 12:01 subprocess.mojopkg -rwxr-xr-x 1 thomas thomas 1487368 31 déc. 12:01 tensor_internal.mojopkg -rwxr-xr-x 1 thomas thomas 1748 31 déc. 12:01 tensor.mojopkg -rwxr-xr-x 1 thomas thomas 1468408 31 déc. 12:01 tensor_utils_internal.mojopkg -rwxr-xr-x 1 thomas thomas 1467 31 déc. 12:01 tensor_utils.mojopkg
环境信息
- magic 0.5.1 - (基于pixi 0.37.0)
- mojo 24.6.0 (4487cd6e)
解决建议
- 修复包权限:先补充缺失的执行权限,执行以下命令:
chmod +x .magic/envs/default/lib/mojo/small_time.mojopkg .magic/envs/default/lib/mojo/lightbug_http.mojopkg
之后重新运行程序验证是否解决。
检查版本兼容性:报错提示字节码版本与当前MLIR版本不匹配,说明
lightbug_http依赖的small_time包是用旧版Mojo编译的,与当前24.6.0版本不兼容。可以:- 指定安装与当前Mojo版本匹配的
lightbug_http版本:magic add lightbug_http@<兼容版本号> magic install - 若找不到兼容预编译包,尝试从源码编译
lightbug_http和small_time,确保使用当前Mojo版本构建。
- 指定安装与当前Mojo版本匹配的
清理重新安装:删除现有环境后重新初始化,避免缓存或版本冲突:
rm -rf .magic magic init hello_web --format mojoproject cd hello_web # 先将渠道配置添加到mojoproject.toml magic add lightbug_http magic install
内容的提问来源于stack exchange,提问作者Thomas Hügel
相关产品推荐
相关产品推荐

