Why I Need Customization
I use my own command to enable conda inside my PowerShell:
Use-Conda # `conda` will be useable only after this command
conda activate some_env_nameThe question is: VS Code doesn't know about this. It will try to activate the selected Python environment directly in my shell, which will fail.
VS Code Customization
{
"python-envs.defaultEnvManager": "ms-python.python:conda",
"python-envs.defaultPackageManager": "ms-python.python:conda",
// disable environment auto activation
"python.terminal.activateEnvironment": false,
// config powershell
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
// here, profile.ps1 should be the place for us to customize
"args": ["-NoExit", "-Command", ". ./profile.ps1"]
}
},
// add this if you want exclude __pycache__ from your file explore in vscode
"files.exclude": {
"**/__pycache__": true,
},
// extra location for import resolution
"python.analysis.extraPaths": [
"${workspaceFolder}/py_impl/packages",
]
}PowerShell Customization
# code.cmd is required instead of code
# code resolves to Code.exe, not code.cmd
# you could check out these two using `gmc` command
. "$(code.cmd --locate-shell-integration-path pwsh)"
Use-Conda
conda activate compilers
function P {
$command = "python " + ($args -join ' ')
Invoke-Expression $command
}
# the extraPaths in vscode customization only works for linters.
# to actually makes it work, we also need to add that path into PYTHONPATH
# env variables.
$env:PYTHONPATH += ";path\to\py_impl\packages;"
没有评论