简体   繁体   English

无法使用 python 导入外部包

[英]Can't import external packages with python

Title.标题。 It just doesn't recognize it.它只是不认识它。 For example, I'm trying to make a discord bot with discord.py.例如,我正在尝试使用 discord.py 制作 discord 机器人。 I do the pip install thingy, and it just spits this out when I try to run my file:我做了 pip install thingy,当我尝试运行我的文件时它只是吐出来:

Traceback (most recent call last):
    File "C:\Users\Pixel\Desktop\Discord bot\bot.py". line 1, in <module>
        import discord
ModuleNotFoundError: No module named 'discord' 

It does exist, I checked: (C:\Python38\lib\site-packages\discord)它确实存在,我检查了:(C:\Python38\lib\site-packages\discord)
Am I doing something wrong here or am I just stupid?我在这里做错了什么还是我只是愚蠢? Thanks!谢谢!

There are many possible reasons for this error.这个错误有很多可能的原因。 You might have multiple versions of Python running on your machine, so you could have installed the module in a version of Python that your code is not using.您的机器上可能运行了多个版本的 Python,因此您可以在代码未使用的 Python 版本中安装模块。

Make sure you're using the write version of Python as your interpreter.确保使用 Python 的写入版本作为解释器。

You could also try installing the module directly in whatever venv you're using by typing this command into the terminal in the same folder python3.9 -m pip install discord .您也可以尝试直接在您正在使用的任何 venv 中安装模块,方法是将此命令输入到同一文件夹中的终端python3.9 -m pip install discord中。 Replace python3.9 with whatever version of Python you're using.python3.9替换为您正在使用的任何版本的 Python。

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

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