So I’m trying to code a discord bot with nextcord, but I have a hiccup.
The nextcord import ONLY works on python version 3.10.11 . If I use any other version of python it cannot resolve the import despite the package being installed properly.
I’ve tried these python versions:
- 3.12.1 (both from the official python website and microsoft store)
- 3.10.0
- 3.10.11 (this works)
- 3.9.13
I have had this issue a few times but managed to get around but now its really annoying me.
Anyone have any fix or any clues as to why it’s behaving like this?
I have tried MULTIPLE python versions, restarting my machine and restarting visual studio code.
What should be happening is that the imports work no matter what version.
EDIT: I would like to add that the nextcord library is installed properly, confirmed since it works with a different version of python. It must be a python 3.12.1 issue then, because dotenv also has the same issue of not being able to be resolved.
2
Answers
I installed python3.11:
This works for me on Windows 11 (in a CMD window):
From comments in a previous answer I noticed that you are probably using Windows. I don’t know how multpile python versions are handled on Windows, but nevertheless I suggest using a virtual environment. Virtual environment are python environments locally installed in your project and allow you to install packages on a per project basis.
There are multiple package managers out there that automatically create a virtual environment with a matching python version and your dependencies for you. I suggest to use
PDM
(https://pdm-project.org/latest/) as it is very beginner friendly in my opinion. PDM will ask you what python version you want to use when installing the first time. But there are also other options (hatch, poetry, flit…)Also make sure to select the python interpeter inside your virtual environment in VSCode so it can find your packages.