1

I wrote a small text to control my fan that is on my raspberry pi 3 version B.

After running the program it came up with an error:

'pi@raspberrypi:~/Development $ Sudo python3.5 run-fan.py
 traceback (most recent call last):
 file "run-fan.py", line 9, in <module>
 import PRi.GPIO as GPIO
 ImportError: No module named 'RPi'

I don't know to much about Python so I don't know what is wrong

Full Script

Feel free to ask anything about the script, I thank you for your help.

Yahya
  • 13,349
  • 6
  • 30
  • 42
Rick Schurink
  • 11
  • 1
  • 1
  • 2

4 Answers4

2

You just need to upgrade the RPi package by the following command

sudo pip install --upgrade RPi.GPIO

If you are using python 3 the command should be like this

sudo pip3 install --upgrade RPi.GPIO
Hemant Arora
  • 61
  • 10
1

You have to install the module first on your Raspberry. Unfortunately I don't have one to test but according this link the command for python 3 should be (you may have to load first the package on the raspberry):

sudo apt-get -y install python3-rpi.gpio

I hope it helps,

Nicolas M.
  • 1,472
  • 1
  • 13
  • 26
  • nope still the same problem, it is still saying 'pi@raspberrypi:~/Development $ Sudo python3.5 run-fan.py traceback (most recent call last): file "run-fan.py", line 9, in import PRi.GPIO as GPIO ImportError: No module named 'RPi' even after restarting the system – Rick Schurink May 22 '17 at 19:23
  • Can you try answers provided at this [link](https://www.raspberrypi.org/forums/viewtopic.php?t=151273&p=992674). Sorry I have no RPi to test this :s I only checked on forums – Nicolas M. May 22 '17 at 19:29
  • I saw that post befor and tried it but does not seem to fix it – Rick Schurink May 22 '17 at 22:37
1

Another solution is when you using GPIO on raspberry pi, you need add sudo.

chilin
  • 420
  • 7
  • 9
0

For me was need to focus on using python3 with permission of sudo so rember to use sudo with python3

sudo python3 filename.py

and maybe need to active SPI by run through Terminal:

sudo raspi-config

Then

Interface Options > SPI then make sure to be activated/enabled

Zaman
  • 811
  • 7
  • 15