简体   繁体   English

如何让python识别安装在虚拟环境中的模块?

[英]how do I get python to recognize modules installed in virtual environment?

I'm having trouble getting python in vs code to work properly.我无法让 python 在 vs 代码中正常工作。 There were problems for a while (i dove right in with a workspace folder) so I decided to set up everything from scratch by starting a new project/workspace folder.有一段时间出现了问题(我直接使用了工作区文件夹),所以我决定通过启动一个新的项目/工作区文件夹从头开始设置所有内容。

so far I've been having a few issues.到目前为止,我遇到了一些问题。 The latest is this: despite creative a virtual environment as instructed on the vs code website, I can't get python to recognize that I've already installed the modules I want to use.最新的是:尽管按照 vs code 网站上的说明创建了一个虚拟环境,但我无法让 python 识别出我已经安装了我想要使用的模块。

How do I fix this?我该如何解决? (please see attached picture. (请看附图。

towards the bottom you can see that the virtual environment already has matplotlib, but python wouldn't recognize the module anyway在底部你可以看到虚拟环境已经有 matplotlib,但无论如何 python 都不会识别该模块

  1. Create your virtual environment (eg I used venv module to create a virtual env called TEST : $python3 -m venv TEST创建您的虚拟环境(例如,我使用 venv 模块创建了一个名为TEST的虚拟环境: $python3 -m venv TEST
  2. From VS code go to Command Palette and type Python: Select Interpreter从 VS 代码转到Command Palette并键入Python: Select Interpreter

在此处输入图片说明

And then you can choose the location of the desired interpreter (in my case the one from TEST virtual environment然后您可以选择所需解释器的位置(在我的情况下是来自TEST虚拟环境的解释器

在此处输入图片说明

  1. You can always test your virtual environment from the terminal, eg TEST env您始终可以从终端测试您的虚拟环境,例如TEST env

Bash重击

来自 Bash

From Cmd/Powershell normally you should run:从 Cmd/Powershell 通常你应该运行:

TEST\Scripts\activate.bat

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

相关问题 如何让 IntelliJ 识别常见的 Python 模块? - How do I get IntelliJ to recognize common Python modules? 如何获取本地安装的 Python 模块的列表? - How do I get a list of locally installed Python modules? 无法让 Python3 识别已安装的模块 - Cannot get Python3 to recognize installed modules 如何从 Python 虚拟环境中删除未使用的已安装包? - How do I remove unused installed packages from Python virtual environment? 我如何使用已安装的 python 模块 - How do i use installed python modules 如何设置 python 虚拟环境? - How do I setup a python virtual environment? 当我已经安装了python 3.6时,如何在运行python(和pipenv)2.7的pycharm中设置虚拟环境? - How do I set up a virtual environment in pycharm which runs python (and pipenv) 2.7 when I already have python 3.6 installed? 如何让python-for-android的安装程序脚本识别Windows系统上安装的pbs? - How do I get python-for-android's installer script to recognize the installed pbs on a Windows system? 如何安装导入numpy、pandas等模块? 我想使用IDLE编辑/运行环境,安装了Python 3.10 - How do I install and import modules such as numpy and pandas? I want to use the IDLE editing/run environment, and I have Python 3.10 installed 如何让我的 conda 环境识别我的 GPU? - How do I get my conda environment to recognize my GPU?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM