I have a dockerfile to create a container with miniconda and install a few packages (trimmed here):
FROM continuumio/miniconda3:4.11.0
# install the necessary packages
RUN conda install -c conda-forge python=3.10.4 \
ipykernel=6.13.0 \
numpy=1.22.3
ENV APP_DIR /app
WORKDIR ${APP_DIR}
CMD /bin/bash
I then use VSCode, with the "remote-containers" extension to "open folder in container".
I then open a python file and hit F5 to run, but it doesn't recognize some packages. I have to click in VSCode lower right corner to change the interpreter from "3.9.2 64-bit"(/usr/bin/python3) to "3.10.4 ('base':conda)" (/opt/conda/bin/python).
Is there a way to avoid this last step? Perhaps adding something to the devcontainer.json file? Main idea so far would be to try to modify the PATH environment variable so that it doesn't detect the 3.9.2 python, or actually delete the 3.9.2 python folder or link using a command in the dockerfile, but those ideas both seem pretty ugly.
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.
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