No module named RPi and RPi._GPIO and apt_pkg

While migrating my python2 app to python3 on Ubuntu-Mate 18.04, I encountered the following error.

File “/home/pi/build/PiMotor.py”, line 8, in
import RPi.GPIO as GPIO
ImportError: No module named ‘RPi’

So, I installed using the following command and received the same error but this time for RPi._GPIO.
sudo apt-get install python3-rpi.gpio

After hours of testing different installation options, found the follow steps fixed the RPi._GPIO problem and operated as expected. Be aware that these files have similar names with numbers that could include 35m, 36m, or 37m. 36m was the only file in the RPi folder.

cd /usr/lib/python3/dist-packages/RPi/
sudo cp _GPIO.cpython-36m-arm-linux-gnueabihf.so _GPIO.so

While testing apt-get install, I encountered the following error:
ImportError: No module named ‘apt_pkg’

To fix that, executed the following commands:
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-arm-linux-gnueabihf.so apt_pkg.so

1 Like