Skip to content

Discord bots

Fixing Python Imports and Virtual Environments for Discord Bots

Make sure the interpreter that starts the bot is the interpreter that has its dependencies installed.

PythonvenvImports
Reading time
2 min read
Published
Updated
Maintained by
EnderHost Team

A Python bot can report ModuleNotFoundError even after a successful package install when startup uses a different interpreter. Check the executable, environment and dependency file together. Repeatedly installing the package globally can make the mismatch harder to see.

Inspect the interpreter in use

python --version
python -m pip --version
python -c "import sys; print(sys.executable)"

Use the same interpreter name that appears in your startup command; it may be python3. The pip output identifies the environment receiving packages. Compare this with the panel runtime rather than assuming your laptop and hosting container share a Python version.

Choose one environment strategy

On a VPS, create an isolated virtual environment for the application. Python virtual environments are intended to be recreated on the target system, not copied between machines. In a managed bot container, follow its installation mechanism; creating an extra environment is unnecessary if startup will not use it.

python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python bot.py

This Linux example assumes your entry point is bot.py and your reviewed dependency file is requirements.txt. Substitute the actual names. If the venv module is unavailable, use the supported runtime image or install the distribution package on a VPS you administer.

Check the remaining failure

  1. Read the first missing module or incompatible-version message.
  2. Check that the dependency is declared; an import name may differ from its package name.
  3. Check for local files named after libraries, such as discord.py, that shadow the installed package.
  4. Install into a fresh test environment and start the same entry point.
  5. Restart the hosted service and confirm that commands and database access work.

Keep a known-working dependency file with your test deployment. Follow the VPS deployment guide when you also manage the operating system.

Sources and references

Hosting documentation. Publication and update dates reflect this edition.

Related articles

Related topics

Hardware we trust. Software you know.

PREPARING YOUR EXPERIENCE