Search code examples
pythonvisual-studio-codevirtualenvinfluxdb

Exception has occurred: ModuleNotFoundError No module named 'influxdb'


I'm maintaining a python file, which contains the following code. It worked fine before, but when I modify the code and debug, it occurs an error, which says "Exception has occurred: ModuleNotFoundError No module named 'influxdb'".

from influxdb import InfluxDBClient

enter image description here

I've already checked whether I installed the package or not, but still not worked.

enter image description here

Any help would be appreciated, thanks!


Solution

  • Make sure you have selected the 'backend' venv in VSCode as well, otherwise it'll be validating your code with the global Python packages.

    You have a shortcut for it in the lower right-corner (in my case the venv is called 'venv' and contains a Python 3.10.10 as opposed to the global Python 3.11). Example below

    VS Code Python environment selector