Search code examples
pythonpippaho

Installed package via pip, but ModuleNotFoundError


OK so I'm on a windows machine, and wanted to use paho-mqtt package. Downloaded official Python 3 installer msi file, and installed python 3, I don't remember any installation of python before this.

>python --version
Python 3.8.1

Next, Installed paho-mqtt via pip

>pip install paho-mqtt
Collecting paho-mqtt
  Using cached https://files.pythonhosted.org/packages/59/11/.../paho-mqtt-1.5.0.tar.gz
Installing collected packages: paho-mqtt
    Running setup.py install for paho-mqtt ... done
Successfully installed paho-mqtt-1.5.0

Tried same command via pip3 and it says the package is already installed.

But when I import paho.mqtt.client as mqtt I get the following error

Traceback (most recent call last):
  File "C:\mqt\paho.py", line 2, in <module>
    import paho.mqtt.client as mqtt
  File "C:\mqt\paho.py", line 2, in <module>
    import paho.mqtt.client as mqtt
ModuleNotFoundError: No module named 'paho.mqtt'; 'paho' is not a package

I've done every solution provided online but no chance.

Also got the installation directory using https://stackoverflow.com/a/49028561/2543240 the paho directory is there and contains py files.

Is there any debugging command that can help such conditions, to see where is python actually looking for the files it wants to load and can't?

Any help would be greatly appreciated.

Edit

Simply import paho returns no error. but import paho.mqtt leads to

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

So installing and uninstalling makes some difference, but just for import paho not import paho.mqtt or import paho.mqtt.client as mqtt. for the later imports the error message is there whether i install or uninstall paho-mqqt.


Solution

  • If you name your source file as paho.py, it could hide the paho package.

    So renaming paho.py to paho2.py should fix the problem.