[英]Select interpreter of docker container in the vscode
In vscode, we can install the python extension, then select the interpreter which we want, like python in the conda environment.在 vscode 中,我们可以安装 python 扩展,然后选择我们想要的解释器,比如 conda 环境中的 python。
So we can use "shift" + "enter" key for running the code line by line in the terminal.所以我们可以使用“shift”+“enter”键在终端中逐行运行代码。 For managing different virtual environment, using docker container is a better way.
对于管理不同的虚拟环境,使用 docker 容器是一种更好的方法。
If I already install the docker, and pull the python image.如果我已经安装了 docker,并拉取了 python 图像。 How to select the interpreter which is created in the docker container?
如何选择在 docker 容器中创建的解释器? Not just remote to the docker container.
不只是远程到 docker 容器。
Tested on VSCode 1.61:在 VSCode 1.61 上测试:
Remote-Containers
extensionRemote-Containers
扩展Remote-Containers: Attach to Running Container...
, then select the running Docker containerRemote-Containers: Attach to Running Container...
,然后选择正在运行的 Docker 容器Get Started
page, click the Open...
and enter the path to the Docker volume mounted to your source code.Get Started
页面上,单击Open...
并输入安装到源代码的 Docker 卷的路径。 It must be set to the same path as WORKDIR
in your Dockerfile-local
, eg to /app
.Dockerfile-local
中的WORKDIR
相同的路径,例如/app
。Python
extension on the containerPython
扩展Python: Select Interpreter
, then select the Docker interpreterPython: Select Interpreter
,然后选择 Docker 解释器Python: Configure Tests
, then select the framework you usePython: Configure Tests
,然后选择您使用的框架Source: https://dev.to/alvarocavalcanti/setting-up-a-python-remote-interpreter-using-docker-1i24资料来源: https ://dev.to/alvarocavalcanti/setting-up-a-python-remote-interpreter-using-docker-1i24
UPD. UPD。
Remote development extensions
seem to be one of the main focuses in VSCode development currently, eg the newer versions have got the Remote explorer
Activity tab enabled by default, which allows much more intuitive approach to connecting to Docker containers. Remote development extensions
似乎是目前 VSCode 开发的主要焦点之一,例如,较新的版本默认启用了Remote explorer
Activity 选项卡,这允许更直观地连接到 Docker 容器。 Check release notes here: https://github.com/microsoft/vscode-docs/tree/main/remote-release-notes在此处查看发行说明: https ://github.com/microsoft/vscode-docs/tree/main/remote-release-notes
在 vscode 创建的devcontainer.json
文件中,您有image
键,它的值是图像的路径,如果您想使用更改 python 版本,您可以在此处执行此操作或使用 vscode 文档中的快速说明
I think it's impossible, I am afraid you must remote to the docker container.我认为这是不可能的,恐怕你必须远程到 docker 容器。
I really can't imagine out you taking a python interpreter in Linux to work on windows directly.我真的无法想象你在 Linux 中使用 python 解释器直接在 Windows 上工作。
If your objective is to have vscode to work on a local project and run it with a docker-based interpreter, the solution is: mounting the local project directory to the docker container that contains the interpreter, then in vscode open the project directory (mounted) from the container.如果您的目标是让 vscode 在本地项目上工作并使用基于 docker 的解释器运行它,则解决方案是:将本地项目目录安装到包含解释器的 docker 容器中,然后在 vscode 中打开项目目录(已安装) 从容器中。
How to mount your project directory:如何挂载你的项目目录:
docker run -v /user/localproject:/root/mountedproject
https://docs.docker.com/storage/volumes/ https://docs.docker.com/storage/volumes/
I have tested it.我已经测试过了。 It should work.
它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.