简体   繁体   English

如何在 VS Code 中安装外部 python 库?

[英]How do you install external python libraries in VS Code?

I have been using VS Code for a few months for coding in python 3.7.2 for both my school and personal projects.几个月来,我一直在使用 VS Code 在 python 3.7.2 中为我的学校和个人项目进行编码。 But I am stuck at a stage when I tried to code a discord bot in python.但是当我尝试在 python 中编写 discord 机器人时,我陷入了困境。 I used pip to install the discord library last night but for some reason when I import discord , it throws an error:我昨晚使用 pip 安装 discord 库,但由于某种原因,当我import discord时,它会引发错误:

File "c:/Users/Jyotirmay Kumar Jha/VS Code Projects/discord/test.py", line 2, in <module>
    import discord
ModuleNotFoundError: No module named 'discord'

I have installed python in the directory "C:\Python\Python37\python.exe" but I am really not sure if the discord module got installed in that location because that is the python interpreter that VS Code is using.我已经在目录“C:\Python\Python37\python.exe”中安装了 python,但我真的不确定 discord 模块是否安装在该位置,因为这是 python 代码正在使用的解释器。

在此处输入图像描述

So, I tried browsing the web to find the actual method to install a module that can be used by VS Code too but they all suggested that I use windows command prompt for it which I had actually done.因此,我尝试浏览 web 以找到安装 VS Code 也可以使用的模块的实际方法,但他们都建议我使用 windows 命令提示符,这是我实际完成的。

What I want to ask is how to get that discord module to work in Visual Studio Code too?我想问的是如何让 discord 模块也可以在 Visual Studio Code 中工作? And for future, how do I know if a module is installed on my device?对于未来,我如何知道我的设备上是否安装了模块?

Make sure to use something along the lines of python3 -m pip install discord.py as python3 uses a separate pip version.确保使用类似于python3 -m pip install discord.py的内容,因为 python3 使用单独的 pip 版本。 Looking at https://github.com/Rapptz/discord.py/issues/228 , it seems there's also a dead/not real package under the same name that doesn't work.看着https://github.com/Rapptz/discord.py/issues/228 ,似乎还有一个死的/不是真正的 package 在同名下不起作用。

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

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