I am creating a docker containing python and php. I am writing a python script to connect to a MQTT broker residing in another docker.
In my dockerfile I ensure that I install the paho client by using the following commands:
RUN apt-get install -y python3-dev
RUN apt-get install -y libffi-dev
RUN apt-get install -y libssl-dev
ADD https://bootstrap.pypa.io/get-pip.py /tmp/get-pip.py
RUN cat /tmp/get-pip.py | python3
RUN pip install paho-mqtt
RUN pip install python-etcd
However when I run the python script I get the following error:
ImportError: No module named paho.mqtt.client
The docker installation does not show any error with regards to paho-mqtt installation. It will be great if someone can guide on this.
I think I have found the problem,
You have installed
Python3but for some reason the interpreter defaults to version 2.7 in Linux.Try using
pip3 install paho-mqtt python-etcdinstead.Or if it does not work, you can literally copy and paste the
pahofolder from yourPython2.7site-packagesfolder to yourPython3site-packagesfolder. I have just verifiedpaho-mqtt 1.2forPython2is exactly the same aspaho-mqtt 1.2forPython3using aMelddiff tool. Please note, when you directly copy and pastepip listwill not display the package you copied.site-packagesare usually inside your systemlibfolder. It depends upon howPythonis installed. In my case everything is inside$HOME/.pyenvfolder.Remember
Python2has it's ownsite-packagesfolder andPython3has it's ownsite-packagesfolder wherePythonsearches for the packages. Sometimes if you are using aDebianbased Linux distro please make sure to check inside thedist-packagesfolder as well to see if you can find the package you are looking for.