I'm trying to create a devcontainer.json that will create a Python virtual environment and activate it in the terminal immediately.
I use postCreateCommand to create the environment, and that seems to work:
"postCreateCommand": "python3 -m venv .venv",
But I haven't figured out how to get the terminal to always activate it. I've tried adding this setting:
"settings": {
"python.terminal.activateEnvInCurrentTerminal": true
}
As well as post*Commands:
"postAttachCommand": ". .venv/bin/activate",
"postStartCommand": ". .venv/bin/activate",
"postCreateCommand": ". .venv/bin/activate",
They don't seem to reliably activate it. I think postAttachCommand worked sometimes, but not always.
When you also set the defaultInterpreterPath-setting it works as expected:
"settings": {
"python.terminal.activateEnvInCurrentTerminal": true,
"python.defaultInterpreterPath": ".venv/bin/python",
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With