Mycroft Community Forum

Import Error: No module named mycroft.messagebus.client.ws

Hello,

I tried pushing my edited code (button.py) to git and had to make few changes in order to push it to git.
The code was working perfectly before these changes (created/copied folders). But right now I am getting this error message.

-----------ERROR MESSAGE-----------------------
File “button.py”, line 23, in
from mycroft.messagebus.client.ws import WebsocketClient
ImportError: No module named mycroft.messagebus.client.ws
-----------ERROR MESSAGE-----------------------

Can somebody suggest me how to get this missing module?
Re-installing would be an option but I#m guessing that there can be a workaround.
Any help is appreciated.

Thanks,
Best,
Wesley

Hi there @vailshery - are you able to paste a GitHub link to the button.py code so we can take a look?
Best, Kathy

Hello @KathyReid,

I had no time since the timeline was tight and I re-installed it.
However, I have a project (small alterations) where
1, Simple button press- Introduces itself
2, Long press-Provides Logic HIGH on one of the GPIOs.

Simple project but it could be used to integrate with bigger projects.

I can share it later if it actually helps because its pretty simple;)
However, I am making notes of all the errors which were rectified during this project.

Best,
Wesley

Hello @KathyReid,

I restarted the Raspi and I get the following error:

------------------------ERROR---------------------------------
Started press
Button pressed 0
/usr/bin/python: No module named mycroft.messagebus
Traceback (most recent call last):
File “/home/pi/mbus.py”, line 5, in
from websocket import create_connection
ImportError: No module named websocket
------------------------ERROR---------------------------------

And my button. py code is:

-----------------------------------------CODE--------------------------------------------------------
import time
import RPi.GPIO as GPIO
from subprocess import call

gpio_pin=23 # The GPIO pin the button is attached to
longpress_threshold=2 # If button is held this length of time, tells system to leave light on
GPIO.setmode(GPIO.BCM)
GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.OUT)
while True:
time.sleep(0.2)
if GPIO.input(gpio_pin) == False: # Listen for the press, the loop until it steps
print "Started press"
pressed_time=time.time()
while GPIO.input(gpio_pin) == False:
time.sleep(0.2)
pressed_time=time.time()-pressed_time
print “Button pressed %d” % pressed_time
if pressed_time<longpress_threshold:
GPIO.output(27,GPIO.LOW)
call([‘python’, ‘-m’, ‘mycroft.messagebus.send’, ‘recognizer_loop:utterance’, ‘{“utterances”: [“introduction”]}’])
time.sleep(10)
call([‘python’, “/home/pi/mbus.py”, “localhost”, “mycroft.mic.listen”])
else:
GPIO.output(27,GPIO.LOW)
call([‘python’, ‘-m’, ‘mycroft.messagebus.send’, ‘recognizer_loop:utterance’, ‘{“utterances”: [“call”]}’])
time.sleep(4)
GPIO.output(27,GPIO.HIGH)
call([‘python’, “/home/pi/mbus.py”, “localhost”, “mycroft.stop”])
GPIO.cleanup()
-----------------------------------------CODE--------------------------------------------------------

The code worked perfectly for hours before I shifted the Raspi to another place.

Any help is appreciated.

Best,
Wesley

No idea on this one, I’m going to tag @forslund and see if he has any ideas (sorry to pass another one your way, Ake)

1 Like

Hi, I bet it’s because the mycroft package was updated to the python-3 release.

In this move we also moved mycroft into it’s own virtualenvironment.

You want to activate the virtualenv before running the script

so basically do

source /opt/venvs/mycroft-core/bin/activate
python your_script.py

to have access to the mycroft package.

Hope this helps!
/Åke

1 Like

Hello @forslund,

It threw few errors. But fixed it, Got to test tomorrow if it works.
Will update you.

Best,
Wesley

2 Likes

Hello @forslund,

I tried the above method and I get this error now.

---------------------ERROR--------------------------------------------------------

(mycroft-core) pi@picroft:~ $ python button.py
Traceback (most recent call last):
File “button.py”, line 3, in
import RPi.GPIO as GPIO
ImportError: No module named ‘RPi’

------------------------ERROR-------------------------------------------------------

Tried uninstalling and installing it. But no luck. Any solution for this? This error is something which never came up a week ago when the button was working fine :wink:

Thanks in advance.

Best,
Wesley

Ah right.

This is due to the changes we made to the packaging, separating the mycroft environment from the normal environment (This so we don’t break other packages and don’t get broken ourselves).

At this point the RPi.GPIO module is installed in the system but not in the venv and the mycroft module is installed in the venv but not in the system.

To install the Rpi.GPIO module into the mycroft-core venv run the following

sudo su
source /opt/venvs/mycroft-core/bin/activate
pip install RPi.GPIO
exit

This should fix above issue.

/Åke

Hello @forslund,

It did not fix the issue. I re-installed and edited the pre-installed skills to match my requirements and it works like a charm now. I do not know how they are connected.

Best,
Wesley

And a strange thing happens again. It was working fine and I get this error.
There was an update which was running and now I get the same error

----------------------------------ERROR------------------------------------------
Button pressed 2
Traceback (most recent call last):
File “/home/pi/mbus.py”, line 5, in
from websocket import create_connection
ImportError: No module named websocket
/usr/bin/python: No module named mycroft.messagebus
^CTraceback (most recent call last):
File “button.py”, line 30, in
time.sleep(0.2)
KeyboardInterrupt

-----------------------------------ERROR---------------------------------------------

Best,
Wesley