import discord gives me an error on

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

File "", 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 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...


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

  at /opt/virtualenvs/python3/lib/python3.8/site-packages/poetry/puzzle/ 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)
      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?

>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 it works differently. Some of them might be missing.

Fixing your error:

Open your file in 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.


An alternative method is to make a requirements.txt file and write 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")

Leave a Reply