我正在尝试调试一些必须在Mamba环境中运行的Python代码。为了运行代码(但不是调试),我可以打开Miniforge提示符命令行应用程序,激活我的环境(mamba activate my_env),然后运行我的python (python my_file.py)。运行此代码将产生一个错误,我希望使用调试接口来追溯该错误。我想让它在Visual代码中运行是有问题的,因为它似乎无法运行Miniforge提示符命令行。我也在Windows 10上运行。
VSCode中的默认终端选项(适用于Windows)是Powershell和CMD (和Git ),这两个选项都工作得很好,但是当我为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",
}我还修改了launch.json,一旦在微型锻造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"],
}
]
}另外,下面是实际激活环境的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"
}]
}当我在VSCode中执行任何代码(在运行或调试中)时,它似乎只是在标准的CMD终端上运行,而不是在指定的Mamba环境中运行。如果有人知道如何使其工作,或者在VSCode中调试python时以任何方式激活Mamba环境,那么任何帮助都将是非常感谢的!
发布于 2022-06-06 22:37:29
我遇到了这个问题,试图配置我的VS代码终端,以发挥良好的迷你锻造。在稍微修改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"
},发布于 2022-09-11 18:38:22
有一个vscode扩展https://github.com/mamba-org/vscode-micromamba
有了这个扩展,就可以创建基于environment.yml文件的mamba环境。在mamba环境旁边生成一个.env文件。如果使用python扩展,可以将其配置为使用.env文件。当使用终端窗口时,环境会自动激活。
https://stackoverflow.com/questions/72092716
复制相似问题