Peter Wiley
Peter Wiley

Reputation: 840

Raspberry Pi: How to get RPi.GIPO working with Python 3.6?

I have installed Python 3.6 using the instructions at https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f

For reasons I don't fully understand Python 3.6.5 was placed in

/home/pi/Python-3.6.5

and some modules were not available.

I installed RPi.GPIO into /home/pi/Python-3.6.5/Lib using

pip install RPi.GPIO -t .

Attempting to run a script with sudo python3.6 /home/pi/PythonProjects/omxcall_radar.py produces this error:

Traceback (most recent call last):
  File "/home/pi/PythonProjects/omxcall_radar.py", line 18, in <module>
  import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

However the RPi directory is in the Lib directory

I am working at the limit of my linux skills. Can someone please explain why I am getting the error and/or what I may have done wrong in installing Python 3.6/RPi.GIPO?

Upvotes: 0

Views: 850

Answers (1)

larsks
larsks

Reputation: 312263

There's a lot going on here.

The Python-3.6.5 directory in /home/pi is the Python source code. It's there because that's where you unpacked the Python-3.6.5.tar.xz archive you retrieved using wget. It is not where Python was installed.

When you ran sudo make altinstall, that installed Python into /usr/local (specifically, the binary itself would be /usr/local/bin/python3.6).

When you ran pip install RPi.GPIO -t ., you installed the RPi.GPIO module into your current directory, but that's not anywhere that your newly installed Python would look for it. Additionally, the pip you were using doesn't know anything about your new Python install, either.

After running make altinstall, you should probably do the following:

  1. Install pip for your new Python install:

    easy_install-3.6 pip
    
  2. Use pip3.6 to install RPi.GPIO:

    pip3.6 install RPi.GPIO
    
  3. Finally, run your script using your new Python:

    python3.6 /home/pi/PythonProjects/omxcall_radar.py
    

You may or may not need sudo, depending on what sort of access your script requires.

Upvotes: 1

Related Questions