python - devcontainer.json for VScode using existing Container - Stack Overflow
docker - VSCode remote-container default python interpreter - Stack Overflow
How fix Python import error in VS Code editor when using a Dev Container? - Stack Overflow
What kind of extensions should be installed inside a Dev Container?
Videos
This question is a bit old now but I found it first on google searching for the same thing.
The setting that's worked for me as of Nov 2023 is:
devcontainer.json
{
"name": "python dev",
"image": "python:3.10",
"customizations":{
"vscode": {
"extensions":[
"ms-python.python",
"ms-python.vscode-pylance"
],
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python"
}
}
}
}
In case that's not enough, I also have "python.defaultInterpreterPath": "/usr/local/bin/python", copied into .vscode/settings.json just to be certain.
Did you try to add a "settings" field in your devcontainer.json so you can specifiy python.pythonPath value ?
Like this :
// devcontainer.json
{
"name": "My devcontainer",
"settings": {
"python.pythonPath": "/opt/conda/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-azuretools.vscode-docker",
]
}
I often have this same issue with Python+Devcontainer. What works for me is:
setting this env variable:
export PYTHONPATH=/workspace, you can also try with/workspacesor/yourProjectNamedepending on your setup.restart the Python Language Server with
Ctrl+Shift+P>Python: Restart Language Server.
Note that you do not need to rebuild the container. When you find the correct value for PYTHONPATH, you can add it to your Devcontainer configuration.
Is this issue completely resolved? I believe it has to do something with your directory structure.
Please have a look at recommended directory structure here
.devcontainer/
devcontainer.json
.devcontainer/
Dockerfile
README.rst
LICENSE
setup.py
requirements.txt
foo/
__init__.py
foo/
bar.py
tests/
test_bar.py
docs/
conf.py // optional
docs/
index.rst // optional
If you don't want to disturb your directory structure, you may consider below two entries:
- In the
devcontainer.jsonfile, givecontext:"." - In the
Dockerfile, adding appropriate entry forWORKDIR