简体   繁体   English

VSCODE 不再检测 python 虚拟环境

[英]VSCODE no longer detecting python virtual environment

On Windows.在 Windows 上。

Normally, when I run通常,当我跑步时

python -m venv myvenv

In the bottom right corner, VSCODE will detect this virtual environment and prompt me to set it as default interpreter.在右下角,VSCODE 会检测到这个虚拟环境并提示我将其设置为默认解释器。

In fact, this was working up to about 30 minutes ago.事实上,这在大约 30 分钟前还有效。

However, I was having errors with path in Git Bash and followed instructions here to change my default terminal back to the CMD.但是,我在 Git Bash 中的路径出现错误,并按照此处的说明将我的默认终端更改回 CMD。

After doing so, VSCODE no longer recognizes any virtual environment I create automatically.这样做之后,VSCODE 不再识别我自动创建的任何虚拟环境。 Doing CTRL SHIFT P and trying to set it manually doesn't work either, as it cannot seem to find it.执行 CTRL SHIFT P 并尝试手动设置它也不起作用,因为它似乎找不到它。

However, if I do但是,如果我这样做

source myvenv/Scripts/activate

It does indeed open the virtual environment.它确实打开了虚拟环境。 However, this only lasts for that one terminal session.但是,这只持续到session这一终端。

How can I fix this problem?我该如何解决这个问题?

Try the solution from the below link and do let me know in the comments if that works for you尝试以下链接中的解决方案,如果适合您,请在评论中告诉我

Even though I have referred to the exact section of the page required for your resolution, as suggested by @Ch3steR, I am putting the required details below:-尽管我已经提到了您的解决方案所需的页面的确切部分,正如@Ch3steR 所建议的那样,我仍将所需的详细信息放在下面:-

From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):如果可用,您还可以使用状态栏上的 Select Python 环境选项(它也可能已经显示了选定的解释器):

No interpreter selected未选择翻译

The command presents a list of available interpreters that VS Code can find automatically, including virtual environments.该命令显示 VS Code 可以自动找到的可用解释器列表,包括虚拟环境。 If you don't see the desired interpreter, configure your Python environment.如果您没有看到所需的解释器,请配置您的 Python 环境。

for setting python environment, please follow below instructions: -要设置 python 环境,请按照以下说明进行操作:-

To select a specific environment, use the Python: Select Interpreter command from the Command Palette (⇧⌘P).要 select 特定环境,使用命令面板中的 Python: Select 解释器命令 (⇧⌘P)。

Python: Select Interpreter command Python:Select 解释器命令

You can switch environments at any time;您可以随时切换环境; switching environments helps you test different parts of your project with different interpreters or library versions as needed.切换环境可帮助您根据需要使用不同的解释器或库版本测试项目的不同部分。

The Python: Select Interpreter command displays a list of available global environments, conda environments, and virtual environments. Python: Select 解释器命令显示可用全局环境、conda 环境和虚拟环境的列表。

Note: When using an Anaconda distribution, the correct interpreter should have the suffix ('base':conda), for example Python 3.7.3 64-bit ('base':conda).注意:使用 Anaconda 发行版时,正确的解释器应具有后缀 ('base':conda),例如 Python 3.7.3 64 位 ('base':conda)。

Selecting an interpreter sets the python.pythonPath value in your workspace settings to the path of the interpreter.选择解释器会将工作区设置中的 python.pythonPath 值设置为解释器的路径。 To see the setting, select File > Preferences > Settings (Code > Preferences > Settings on macOS), then select the Workspace Settings tab.要查看设置,select 文件 > 首选项 > 设置(macOS 上的代码 > 首选项 > 设置),然后 select 工作区设置选项卡。

Reference:-参考:-

https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter

https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment

Thanks谢谢

The crisp of VS code Environment setting as per there site:根据那里的站点,VS代码环境设置的清晰:

From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. From within VS Code, select a Python 3 interpreter by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too) The command presents a list of available interpreters that VS Code can find automatically, including virtual environments.如果可用,您还可以使用状态栏上的 Select Python 环境选项(它也可能已经显示选定的解释器)该命令显示了 VS Code 可以自动找到的可用解释器的列表,包括虚拟环境。 If you don't see the desired interpreter, see https://code.visualstudio.com/docs/python/environments如果您没有看到所需的解释器,请参阅https://code.visualstudio.com/docs/python/environments

Note: When using an Anaconda distribution, the correct interpreter should have the suffix ('base':conda), for example Python 3.7.3 64-bit ('base':conda).注意:使用 Anaconda 发行版时,正确的解释器应具有后缀 ('base':conda),例如 Python 3.7.3 64 位 ('base':conda)。

Selecting an interpreter sets the python.pythonPath value in your workspace settings to the path of the interpreter.选择解释器会将工作区设置中的 python.pythonPath 值设置为解释器的路径。 To see the setting, select File > Preferences > Settings (Code > Preferences > Settings on macOS), then select the Workspace Settings tab.要查看设置,select 文件 > 首选项 > 设置(macOS 上的代码 > 首选项 > 设置),然后 select 工作区设置选项卡。

Note: If you select an interpreter without a workspace folder open, VS Code sets python.pythonPath in your user settings instead, which sets the default interpreter for VS Code in general.注意:如果您 select 是一个没有打开工作区文件夹的解释器,VS Code 会在您的用户设置中设置 python.pythonPath,这通常会为 VS Code 设置默认解释器。 The user setting makes sure you always have a default interpreter for Python projects.用户设置确保您始终拥有 Python 项目的默认解释器。 The workspace settings let you override the user setting.工作区设置允许您覆盖用户设置。

Above Paragraph is taken from: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter以上段落摘自: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM