在ArchLinux的vscode中食用sagemath ### 安装插件
在 vscode 中下载一个 code runners 插件
配置插件
按住 Ctrl+Shift+P 打开用户设置(Open User Settings) 搜索 Code-runner 找到对应配置,Executor Map 和 Executor Map By File Extension。 点击 在setting中编辑 添加以下配置,把代码添加在相应函数下
Linux的settings.json配置1 2 3 4 5 6 7 8 9 10
| "files.associations": { "*.sage": "python" }, "code-runner.executorMapByFileExtension": { ".sage": "cd $dir && sage $fileName", ".py" : "python" }, "code-runner.executorMap": { "python": null, }
|
装好 Sage Math 了之后找他它的 bash.exe 路径
Windows的settings.json配置1 2 3 4 5 6 7 8 9 10
| "files.associations": { "*.sage": "python" }, "code-runner.executorMapByFileExtension": { ".sage": "\"C:\\Users\\<USERNAME-CHANGE-ME>\\AppData\\Local\\SageMath 9.0\\runtime\\bin\\bash.exe\" --login -c '/opt/sagemath-9.0/sage $fullFileName'", ".py" : "python" }, "code-runner.executorMap": { "python": null, }
|
📑 命令参数说明: - executorMapByFileExtension 把.sage后缀定义一个启动命令 - files.associations 配置.sage文件支持高亮 - 因为 files.associations 会导致 code-runner 自带的 executorMap 把 python 映射到预置的 python 命令( executorMap 优先级比 executorMapByFileExtension 高),所以把 executorMap 的 python 项写成 null ,再手动指定 executorMapByFileExtension 的 .py 后缀