【问题标题】:ERROR: Could not find a version that satisfies the requirement json==1.0.0错误:找不到满足要求的版本 json==1.0.0
【发布时间】:2021-04-25 12:58:21
【问题描述】:

我正在尝试在 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 是一个内置的 Python 模块。

标签: python json requirements.txt


【解决方案1】:

你不需要安装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
...

查看相关帖子:Automatically create requirements.txt

【讨论】:

    猜你喜欢
    • 2019-10-07
    • 2018-02-09
    • 1970-01-01
    • 2017-07-08
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    相关资源
    最近更新 更多