2

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.

Anjo
  • 127
  • 9
  • Does this answer your question? [Import Error: paho.mqtt.client not found](https://stackoverflow.com/questions/41480256/import-error-paho-mqtt-client-not-found) – Gaëtan GR Sep 21 '22 at 11:13
  • No i tried all the different installation methods in there already. The weird thing is i had it working in my first environment. But now i needed to set up a new one for a different project and it does not work. – Anjo Sep 21 '22 at 11:18
  • Because you have to install it again, you exit your virtual env hence the package is not available anymore – Gaëtan GR Sep 21 '22 at 11:19
  • I did install it again in the new environment. – Anjo Sep 21 '22 at 11:20
  • 2
    Do you have a script named `paho.py`, by any chance? – jasonharper Sep 21 '22 at 13:57
  • Yes. I changed it to test.py and it works... Why is that the Problem? – Anjo Sep 21 '22 at 14:24

1 Answers1

3

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.

kirogasa
  • 627
  • 5
  • 19