-1

I am trying to host my discord bot (coded in Python) on Heroku, but I am facing this error. How do I correctly include the json package in requirements.txt?

bot.py file

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 file

git+https://github.com/Rapptz/discord.py
dnspython==1.16.0
PyNaCl==1.3.0
async-timeout==3.0.1
json==1.0.0
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135

1 Answers1

1

You do not need to install the json module, because it is a built-in module with Python.

Just import json and it should just work out-of-the-box. If you are using some other JSON library, then it's probably not named as json because Python already has that. You will have to search PyPi for the correct name of the package: https://pypi.org/search/?q=json.

Also, it seems you are manually creating your requirements.txt. You should not need to do that. It's better that you don't because you might miss packages or write incorrect ones (like this json module). You can use 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
...

See related post: Automatically create requirements.txt.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135