Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

import discord gives me an error on repl.it

I’m trying to host a bot on repl.it, and when I was trying to run the bot this error message was shown:

File "main.py", line 2, in <module>
    import discord
ModuleNotFoundError: No module named 'discord'

This seemed weird to me as my code worked perfectly fine last time I tried to run it.
I did some further investigating and found that discord.py has a dependency called aiohttp, so I tried to install the package myself, and then this happened:

Using version ^3.8.1 for aiohttp

Updating dependencies
Resolving dependencies...

  SolverProblemError

  Because discord.py (1.7.3) depends on aiohttp (>=3.6.0,<3.8.0)
   and no versions of discord.py match >1.7.3,<2.0.0, discord.py (>=1.7.3,<2.0.0) requires aiohttp (>=3.6.0,<3.8.0).
  So, because basically-another-discordpy-bot depends on both discord.py (^1.7.3) and aiohttp (^3.8.1), version solving failed.

  at /opt/virtualenvs/python3/lib/python3.8/site-packages/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│ 
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes
exit status 1


Replit: Package operation failed.

What is happening here and how can I fix it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Every time you run your code on your local machine it always have the same configuration (it keeps all your files, installed dependencies, etc.), but on repl.it it works differently. Some of them might be missing.

Fixing your error:

Open your file in repl.it and on your left click "packages" icon and search for discord. Click "+" to install the package. Now it should install every time you run your code.

screenshot


An alternative method is to make a requirements.txt file and write discord.py inside it. Then at the top of your code add this to install required dependencies every time you run your script:

import os
os.system("python -m pip install -r requirements.txt")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading