如何在 VS Code 中使用多个 Python venv
How to use multiple Python venv in VS Code
我有一个带双启动的笔记本,在 Windows 我使用 conda 管理我的 Python 包,在 VS Code select 解释器中向我展示了我所有的 conda env,我已构建,但在 Linux 我正在尝试使用 virtualenv,因为 conda 存在 numpy 问题。
我面临另一个问题,我不知道如何让我的所有环境在 Python select 解释器上显示,就像使用 conda 一样。我知道我可以通过更改 Python 路径找到其中一个环境,但实际上我有 3 个不同的环境,我想 select 解释器显示所有内容,而不必每次都更改路径想使用不同的环境。
我想你需要这个 virtualenvwrapper。在 virtualenv 之上安装它之后。
您将能够使用 workon
命令来 select 您在系统中拥有的不同环境。
只需输入 workon
即可列出可用环境,然后输入 workon <myenv>
至 select。
您确定安装了 "official" Python extension (ms-python.python
) 吗?
它会自动检测多个位置的已知虚拟环境,如described in docs:
The extension automatically looks for interpreters in the following
locations:
- Standard install paths such as
/usr/local/bin
, /usr/sbin
, /sbin
, c:\python27
, c:\python36
, etc.
- Virtual environments located directly under the workspace (project) folder.
- Virtual environments located in the folder identified by the python.venvPath setting (see General settings), which can contain
multiple virtual environments. The extension looks for virtual
environments in the first-level subfolders of venvPath.
- Virtual environments located in a ~/.virtualenvs folder for virtualenvwrapper.
- Interpreters installed by pyenv.
- A pipenv environment for the workplace folder. If one is found, then no other interpreters are searched for or listed as pipenv
expects to manage all aspects.
- Virtual environments located in the path identified by WORKON_HOME (as used by virtualenvwrapper and pipenv).
- Conda environments that contain a Python interpreter. VS Code does not show conda environments that don't contain an interpreter.
- Interpreters installed in a .direnv folder for direnv under the workspace (project) folder.
例如,我的环境(通过 python3 -m venv
创建)位于 /home/my_username/envs/
目录。例如:
/home/my_username/envs/my_project_1/
/home/my_username/envs/my_project_2/
/home/my_username/envs/my_project_2_py36/
/home/my_username/envs/my_project_2_py34/
- 等等
当我想通过命令面板中的 Python: Select interpreter
命令切换环境时,扩展会自动提供它们。
... 或者,您应该能够使用 vscode.
底部的小部件,而不是使用命令面板
我有一个带双启动的笔记本,在 Windows 我使用 conda 管理我的 Python 包,在 VS Code select 解释器中向我展示了我所有的 conda env,我已构建,但在 Linux 我正在尝试使用 virtualenv,因为 conda 存在 numpy 问题。
我面临另一个问题,我不知道如何让我的所有环境在 Python select 解释器上显示,就像使用 conda 一样。我知道我可以通过更改 Python 路径找到其中一个环境,但实际上我有 3 个不同的环境,我想 select 解释器显示所有内容,而不必每次都更改路径想使用不同的环境。
我想你需要这个 virtualenvwrapper。在 virtualenv 之上安装它之后。
您将能够使用 workon
命令来 select 您在系统中拥有的不同环境。
只需输入 workon
即可列出可用环境,然后输入 workon <myenv>
至 select。
您确定安装了 "official" Python extension (ms-python.python
) 吗?
它会自动检测多个位置的已知虚拟环境,如described in docs:
The extension automatically looks for interpreters in the following locations:
- Standard install paths such as
/usr/local/bin
,/usr/sbin
,/sbin
,c:\python27
,c:\python36
, etc.- Virtual environments located directly under the workspace (project) folder.
- Virtual environments located in the folder identified by the python.venvPath setting (see General settings), which can contain multiple virtual environments. The extension looks for virtual environments in the first-level subfolders of venvPath.
- Virtual environments located in a ~/.virtualenvs folder for virtualenvwrapper.
- Interpreters installed by pyenv.
- A pipenv environment for the workplace folder. If one is found, then no other interpreters are searched for or listed as pipenv expects to manage all aspects.
- Virtual environments located in the path identified by WORKON_HOME (as used by virtualenvwrapper and pipenv).
- Conda environments that contain a Python interpreter. VS Code does not show conda environments that don't contain an interpreter.
- Interpreters installed in a .direnv folder for direnv under the workspace (project) folder.
例如,我的环境(通过 python3 -m venv
创建)位于 /home/my_username/envs/
目录。例如:
/home/my_username/envs/my_project_1/
/home/my_username/envs/my_project_2/
/home/my_username/envs/my_project_2_py36/
/home/my_username/envs/my_project_2_py34/
- 等等
当我想通过命令面板中的 Python: Select interpreter
命令切换环境时,扩展会自动提供它们。
... 或者,您应该能够使用 vscode.
底部的小部件,而不是使用命令面板