user10842950
user10842950

Reputation:

No module named ev3dev2

I am trying to add python code to my robot via ev3dev and Visual studio code. I am able to transfer code onto my robot but my problem is that when ever I try to run the code on my PC on visual studio code I get an error saying unable to import visual studio and when I try to run the code on my ev3 the robot stops for about half a second and then the screen goes blank for about one millisecond and then goes back to the previous screen

I have installed ev3dev from visual studio and I have installed ev3dev-lang-python-ev3dev-stretch onto the SD card so the robot does have the software inside it.

Exception has occurred: ModuleNotFoundError
No module named 'ev3dev2'
  File "C:\Users\User\Documents\implanted\tester.py", line 2, in <module>
    from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, 
SpeedPercent, MoveTank



from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.led import Leds

ts = TouchSensor()
leds = Leds()

print("Press the touch sensor to change the LED color!")

while True:
    if ts.is_pressed:
        leds.set_color("LEFT", "GREEN")
        leds.set_color("RIGHT", "GREEN")
    else:
        leds.set_color("LEFT", "RED")
        leds.set_color("RIGHT", "RED")

What I would expect to happen is that when I run the code no errors should happen and if I run the code on the ev3 when I press the touchsensor it should turn the light on the ev3 the colour it is supposed to turn

Upvotes: 1

Views: 2919

Answers (1)

Daniel J&#228;ckel
Daniel J&#228;ckel

Reputation: 11

I've had the same Problem.

Fore me it worked to put the 'vscode-hello-python-master' file in another folder. In the beginning this folder was in the C:\Users\fbk\Documents folder. But the system had permission issues. So I put it under D:\programs\ev3dev2. In the following step I set up a virtual environment. I typed these 4 lines in the vs code Terminal:

py -3 -m venv .venv

.venv\Scripts\activate

python -m pip install --upgrade pip

pip install python-ev3dev2

As this worked for my windows system, this is the code for non windows systems:

python3 -m venv .venv

. .venv/bin/activate

pip install --upgrade pip

pip install python-ev3dev2

Hope this works for you respectively for all, who have the same problem

Upvotes: 1

Related Questions