Anjo
Anjo

Reputation: 127

No module named 'paho.mqtt'; 'paho' is not a package

resolved I have set up a conda environment with anaconda, with python 3.9 and paho-mqtt 1.6.1. I have also tested an Environment that worked for someone else but it doesn't work on my System. Other packages work, like numpy.

The code fails at the first row import paho.mqtt.client as mqtt wit the error ModuleNotFoundError: No module named 'paho.mqtt'; 'paho' is not a package.

Does anyone have a solution or at least some ideas i could try?

For example if i create a new conda env with conda env --create env python=3.9, and then try to run import numpy it obviously doenst run. Then i do pip install numpy and run it again and it works. Though if i do the same with import paho.mqtt it doesn't work even after pip install paho-mqtt.

Upvotes: 2

Views: 3175

Answers (1)

kirogasa
kirogasa

Reputation: 949

This error:

ModuleNotFoundError: No module named 'paho.mqtt'; 'paho' is not a package

may also occur if you have named the main program file you created as paho.py and try to run it as python paho.py or another file has the name paho.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path (citate: "...if path[0] is the empty string, which directs Python to search modules in the current directory first...").

In this case, rename your program file so that its name does not equal with the name of the imported module.

Upvotes: 4

Related Questions