首页 > 解决方案 > Python 错误 ModuleNotFoundError:没有名为“pypresence”的模块

问题描述

嗨,我是 python 新手,当我尝试运行此代码时,我会知道为什么它会显示 ModuleNotFoundError: No module named 'pypresence':

from pypresence import Presence
import time

client_id = '...'
RPC = Presence(client_id)
RPC.connect()

print(RPC.update(state="Lookie Lookie", details="A test of qwertyquerty's Python Discord RPC wrapper, pypresence!"))

while True:
    time.sleep(15)

此代码复制自https://qwertyquerty.github.io/pypresence/html/info/examples.html

我也已经做了几次 pip install pypresence

标签: python

解决方案


您必须先安装模块。

这样做->pip install pypresence

编辑以在 python3 virtualenv 中安装:

像这样创建一个虚拟环境:

python3 -m venv env

激活env

source env/bin/activate

现在,您在 python 3 环境中(确保它至少是 python 3.5 a/c 到模块要求)。

现在,安装运行脚本所需的模块和其他模块,一切顺利。

pip install pypresence


推荐阅读