I’m trying to set up a Python Discord bot on my Raspberry Pi so it can run continuously. After copying my bot script to the Pi, I’m getting a ModuleNotFoundError: No module named ‘discord’ error when trying to execute it.
The main issue is that when I run pip3 install discord.py, it installs successfully but targets Python 3.4 instead of Python 3.5. My bot requires Python 3.5 to function correctly.
When I attempt python3 -m pip install discord.py, I receive: No module named pip
Checking pip --version shows it’s linked to Python 3.4, but I need it configured for Python 3.5. I’ve already tried downloading and running get-pip.py, but pip still defaults to version 3.4.
How can I properly install the discord.py library for Python 3.5 on Raspberry Pi?
It’s common to face these issues with multiple Python versions on the Raspberry Pi. A virtual environment can help you manage dependencies more effectively. Start by creating one specifically for your Discord bot using python3.5 -m venv discord_bot_env, then enter it with source discord_bot_env/bin/activate. From there, you can install discord.py using pip install discord.py. This way, the library gets installed in the right environment and won’t interfere with the system Python. Always remember to activate the environment before running your bot to keep everything organized.
Had this exact headache on my Pi 3B+ last year. Raspberry Pi OS ships with multiple Python versions and pip gets confused about which one to use. What worked for me was targeting the specific Python version when installing packages. Try python3.5 -m pip install discord.py instead of the generic python3 command. If you get ‘no module named pip’, you need to install pip specifically for Python 3.5. Download get-pip.py again and run python3.5 get-pip.py to install pip for the right Python version. After that, always use python3.5 -m pip for installations to avoid conflicts. You can check which Python versions you have with ls /usr/bin/python* to see what’s available.
Use the full path to python3.5 when installing - /usr/bin/python3.5 -m pip install discord.py should work. If pip still isn’t found, you might need to completely reinstall it for that version. Had the same issue and this fixed it.