The_Indestructible
The_Indestructible

Reputation: 17

no module named pygame.base on lego ev3dev

On my Lego ev3 robot my current project is to add the pygame joystick module into my robot and get it up working so I can use my PS1 remote to control Lego ev3 robot. I have put the WHOLE folder from site-packages in python onto my robot and I am not getting the error no module named pygame but I am getting the error no module named pygame.base and many others like no module named pygame.constants after it.

I have looked at the robot's logfile which shows the errors that the code might have on a file that comes whenever you run the robot. I have tried running the robots python file via my computer and I have also tried it via the robot itself both lead to the same error.

I have tried running the same pygame on my computer with my own python games with pygame that I have tried creating and the games on that work fine with no importing errors what so ever.

I have already tried looking into the pygame's __init__.py code where the error is coming from and the code where all the errors are coming up looks something like this:

The code in the pygame's __init__.py has some imports where I think the error is coming from:

from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
from pygame.compat import geterror, PY_MAJOR_VERSION
from pygame.rwobject import encode_string, encode_file_path
import pygame.surflock
import pygame.color
Color = color.Color
import pygame.bufferproxy
BufferProxy = bufferproxy.BufferProxy
import pygame.math

The actual output from when I run the code either on my robot or via visual studio code is:

Traceback (most recent call last):
  File "/home/robot/drive/main.py", line 10, in <module>
  File "/home/robot/drive/pygame/__init__.py", line 136, in <module>
ImportError: no module named 'pygame.base'

the picture

Upvotes: 0

Views: 378

Answers (1)

furas
furas

Reputation: 142985

Python has list sys.path with folders in which it looks for modules. There is folder site-packages so import can find pygame in site-packages/pygame and pygame.base in site-packages/pygame/base

If you moved pygame to folder /home/robot/drive then you have to add it to sys.path before import

import sys
sys.path.append('/home/robot/drive/')
import pygame

and then it can find pygame in /home/robot/drive/pygame and pygame.base in /home/robot/drive/pygame/base


Normally Python looks for modules in folder in which you run code so import pygame can find /home/robot/drive/pygame without adding folder to sys.path but __init__.py runs in folder /home/robot/drive/pygame so from pygame.base import * will look for /home/robot/drive/pygame/pygame/base and there is to many pygame in path. If it would use relative path from .base import * then it would search in /home/robot/drive/pygame/./base which means /home/robot/drive/pygame/base so it would use correct path and it would work without adding folder to sys.path

Upvotes: 0

Related Questions