简体   繁体   English

Visual Studio Code Venv 使用错误 Python 版本

[英]Visual Studio Code Venv Used Wrong Python Version

I have Python 3.4 and 3.9 installed.我安装了 Python 3.4 和 3.9。 I chose the former through the Command Palette and then (also through the Command Palette) created a virtual environment with Venv.我通过 Command Palette 选择了前者,然后(也通过 Command Palette)用 Venv 创建了一个虚拟环境。 I create a new terminal, enter python --version, and it says 3.9 instead of 3.4.我创建了一个新终端,输入 python --version,它显示 3.9 而不是 3.4。

How do I go about fixing this?我如何解决这个问题 go?

There are multiple python environments on your machine, if you have created a virtual environment, you should run these commands after activation.你的机器上有多个 python 环境,如果你创建了虚拟环境,你应该在激活后运行这些命令。 If you execute the python command in a terminal where the virtual environment is not activated, the displayed version will be the one configured in the system environment variable path .如果在没有激活虚拟环境的终端执行python命令,显示的版本就是系统环境变量路径中配置的版本。

The correct way is:正确的做法是:

  1. Create a virtual environment创建虚拟环境
  2. Activate the virtual environment激活虚拟环境
  3. Execute python commands执行 python 命令

There are two ways to activate a virtual environment:激活虚拟环境有两种方式:

  • After creating the virtual environment use the following command to activate创建虚拟环境后使用以下命令激活

    .venv\scripts\activate
  • Or select the virtual environment interpreter in the select interpreter panel, and then create a new terminal to automatically activate the environment.或者select select 解释器面板中的虚拟环境解释器,然后新建一个终端自动激活环境。

    在此处输入图像描述

In vscode, the interpreter version you choose for python will always be displayed in the lower right corner.在vscode中,你为python选择的解释器版本会一直显示在右下角。

在此处输入图像描述

See the Environments documentation for more details.有关详细信息,请参阅环境文档。

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

相关问题 Visual Studio Code 运行 venv python - Visual Studio Code run venv python Visual Studio Code 使用错误的 Python 版本——正确的版本没有显示出来 - Visual Studio Code Using wrong Python Version--correct version does not show up Visual Studio Code 中的 Python 版本问题 - Python version problem in Visual Studio Code 在Windows上从bash运行venv在Visual Studio Code中配置Python路径 - Configure Python Path in Visual Studio Code with venv running from bash on Windows Python -m venv 停止在 Visual Studio Code 中打开虚拟环境并且没有给出错误 - Python -m venv stopped opening virtual environment in Visual Studio Code and gives out no error Visual Studio Code 在打开集成终端时自动激活 python venv - Visual Studio Code auto activate python venv when open integrated terminal Python venv(虚拟环境)使用错误版本的Python - Python venv (virual environment) uses wrong version of Python 如何在 Visual Studio 中为 Python 激活 VENV? - How can I activate VENV for Python in Visual Studio? 为什么 macOS Visual Studio Code 使用错误的 Python 解释器? - Why Is macOS Visual Studio Code Using Wrong Python Interpreter? Visual Studio Code中的调试和运行模式中使用的不同python环境 - Different python environments used in debug and run mode in Visual Studio Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM