sta*_*321 9 python visual-studio-code mamba mini-forge
我正在尝试调试一些必须在 Mamba 环境中运行的 Python 代码。为了运行代码(但不是调试),我可以打开 Miniforge Prompt 命令行应用程序,激活我的环境 ( mamba activate my_env),然后运行我的 python 文件 ( python my_file.py)。运行此代码会产生一个错误,我想使用 Visual Studio Code 调试界面追溯该错误。我在尝试让它在 Visual Studio Code 中运行时遇到问题,因为它似乎无法运行 Miniforge Prompt 命令行。我也在 Windows 10 上运行。
VSCode 中的默认终端选项(适用于 Windows)是 Powershell 和 CMD(以及 Git Bash),它们都工作正常,但是,当我为 Miniforge 添加另一个终端方法(通过 settings.json)时,它似乎并不好好工作。
这是我的 settings.json 文件:
{
...,
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
},
"MambaPython": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": ["\"/K\"", "C:\\ProgramData\\mambaforge\\Scripts\\activate.bat", "C:\\ProgramData\\mambaforge"],
"icon": "terminal-cmd"
}
},
"terminal.integrated.defaultProfile.windows": "MambaPython",
}
Run Code Online (Sandbox Code Playgroud)
我还修改了 launch.json,以便在 miniforge CLI 中运行后激活 mamba 环境。这是我的 launch.json 文件:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
},
{
"name": "Python: ProjectEnv",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"preLaunchTask": "ProjectEnv_activate",
"args": ["--kwarg_one=Something", "--kwarg_two"],
}
]
}
Run Code Online (Sandbox Code Playgroud)
另外,这里是实际激活环境的tasks.json 文件:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [{
"label": "ProjectEnv_activate",
"command": "mamba activate ProjectEnv",
"type": "shell"
}]
}
Run Code Online (Sandbox Code Playgroud)
当我在 VSCode 中执行任何代码(运行或调试)时,它似乎只是使用标准 CMD 终端运行,而不是在指定的 Mamba 环境中运行。如果有人知道如何让它工作,或者在 VSCode 中调试 python 时激活 Mamba 环境的任何方法,我们将不胜感激!
我在尝试配置 VS Code 终端以与 miniforge 配合使用时遇到了这个问题。在稍微摆弄了一下 args 语法后,我就让它正常工作了。我使用的是 conda,而不是 mamba,但我认为这对于激活环境并不重要。
"Command Prompt": {
"path": [
"${env:windir}\\System32\\cmd.exe"
],
"args": ["/K", "C:\\Users\\johndoe\\AppData\\Local\\miniforge3\\Scripts\\activate.bat","C:\\Users\\johndoe\\AppData\\Local\\miniforge3\\envs\\base" ],
"icon": "terminal-cmd"
},
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6087 次 |
| 最近记录: |