ERROR: Could not find a version that satisfies the requirement json==1.0.0

ERROR: Could not find a version that satisfies the requirement json==1.0.0

我正尝试在 Heroku 上托管我的 discord 机器人(编码为 Python),但我遇到了这个错误。如何在 requirements.txt 中正确包含 json 包?

bot.py 文件

from discord.ext import commands
import json


def get_prefix(client, message):
    with open("prefixes.json", "r") as f:
        prefixes = json.load(f)
    return prefixes[str(message.guild.id)]

requirements.txt 文件

git+https://github.com/Rapptz/discord.py
dnspython==1.16.0
PyNaCl==1.3.0
async-timeout==3.0.1
json==1.0.0

您不需要安装 json 模块,因为它是 built-in module with Python.

只需 import json,它应该开箱即用。如果您正在使用某些 other JSON 库,那么它可能不会被命名为 json 因为 Python 已经有了。您必须在 PyPi 中搜索包的正确名称:https://pypi.org/search/?q=json.

此外,您似乎正在手动 创建您的 requirements.txt。你不应该这样做。最好不要这样做,因为您可能会错过包或编写不正确的包(例如 json 模块)。您可以使用 pip freeze:

$ pip freeze > requirements.txt
$ cat requirements.txt
aiohttp==3.7.3
appnope==0.1.2
async-timeout==3.0.1
attrs==20.3.0
backcall==0.2.0
certifi==2020.12.5
chardet==3.0.4
click==7.1.2
datasize==1.0.0
decorator==4.4.2
elasticsearch==7.10.1
elasticsearch-dsl==7.3.0
Flask==1.1.2
...

查看相关 post: