我有一個 dockerfile 來創建一個帶有 miniconda 的容器并安裝一些包(在此處修剪):
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
然后我使用 VSCode,將“remote-containers”擴展名為“在容器中打開檔案夾”。
然后我打開一個 python 檔案并按 F5 運行,但它不識別某些包。我必須單擊 VSCode 右下角將解釋器從“3.9.2 64-bit”(/usr/bin/python3)更改為“3.10.4('base':conda)”(/opt/conda/bin /Python)。
有沒有辦法避免這最后一步?也許在 devcontainer.json 檔案中添加一些東西?到目前為止的主要想法是嘗試修改 PATH 環境變數,使其不檢測 3.9.2 python,或者使用 dockerfile 中的命令實際洗掉 3.9.2 python 檔案夾或鏈接,但這些想法似乎真是丑。
uj5u.com熱心網友回復:
您是否嘗試在您的中添加“設定”欄位devcontainer.json以便您可以指定python.pythonPath值?
像這樣 :
// 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",
]
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478428.html
