Reputation: 5674
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.
Upvotes: 0
Views: 3468
Reputation: 112
You have to mention the version of Python, when normal pip
is not working.
Install by using sudo pip3 install paho-mqtt
Upvotes: 0
Reputation: 95110
Your script C:\mqt\paho.py
when being run is used by Python import system as a module paho
so import paho
works but import paho.mqtt
doesn't because paho.py
is considered by Python as a module, not a package.
Rename your script. And please remember the experience for the future: never give your scripts the same names as existing modules or packages, especially modules or packages from the standard library. For example, always avoid naming your scripts email.py
or test.py
.
Upvotes: 4
Reputation: 26895
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.
Upvotes: 5
Reputation: 54
You might not be calling the same python
when you run pip
.
You can guarantee that you're running pip inside of the correct Python 3.8.1 instance by running:
python -m pip install paho-mqtt
Does that help you at all?
Upvotes: 1