, but when i start: sudo led.pysudo pip3 install RPi.GPIO
I have error:
Code: Select all
import RPi.GPIO as GPIO
ImportError: No module named 'RPi', but when i start: sudo led.pysudo pip3 install RPi.GPIO
Code: Select all
import RPi.GPIO as GPIO
ImportError: No module named 'RPi'Code: Select all
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-rpi.gpioCode: Select all
pi@rpi2b ~/ivan $ python3
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO.setmode(GPIO.BCM)
>>>
Code: Select all
pi@rpi2b ~/ivan $ cat led.py
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
print("Import test completed OK.")
Code: Select all
pi@rpi2b ~/ivan $ python3 led.py
Import test completed OK.
Code: Select all
pi@rpi2b ~/ivan $ sudo led.py
sudo: led.py: command not found
Code: Select all
pi@rpi2b ~/ivan $ sudo ./led.py
./led.py: 1: ./led.py: import: not found
./led.py: 2: ./led.py: import: not found
./led.py: 4: ./led.py: Syntax error: word unexpected (expecting ")")
Code: Select all
pi@rpi2b ~/ivan $ cat led2.py
#!/usr/bin/python3
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
print("Import test completed OK.")
pi@rpi2b ~/ivan $ sudo ./led2.py
Import test completed OK.
Code: Select all
#!/usr/bin/env pythonDougieLawson wrote:You're missing a shebang line.
AddThen run with sudo ./led.pyCode: Select all
#!/usr/bin/env python
Or run with sudo python ./led.py
To the top on a new line.Ivan219 wrote:Where I must add this line?DougieLawson wrote:You're missing a shebang line.
AddThen run with sudo ./led.pyCode: Select all
#!/usr/bin/env python
Or run with sudo python ./led.py
You could read my reply, where I give an example of using this.Ivan219 wrote:Where I must add this line?
Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-rpi.gpioAlso i tried install via pip3 and it was successful, but if i even do:The following packages have unmet dependencies:
python3-rpi.gpio : Depends: python3 (< 3.3) but 3.4.2-2 is to be installed
E: Unable to correct problems, you have held broken packages.
After uninstall via pip3 and install again, i got this againpi@raspberrypi ~ $ sudo python3
Python 3.4.2 (default, Jun 7 2016, 13:30:50)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'RPi'
or#!/usr/bin/python3
i have the same error#!/usr/bin/env python
Code: Select all
rm /usr/bin/python3
ln -s /usr/local/bin/python3 /usr/bin/
ln -s /usr/local/bin/pip3 /usr/bin/won't properly remove or delete python, they will however break your Python installation making it difficult to add, remove, or get anything to work.Ivan219 wrote:rm /usr/bin/python3
ln -s /usr/local/bin/python3 /usr/bin/
ln -s /usr/local/bin/pip3 /usr/bin/
Code: Select all
sudo apt-get purge python3-pip
sudo apt-get purge python3-rpi.gpio
sudo apt-get purge python3*Code: Select all
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgradeCode: Select all
sudo apt-get install python3Code: Select all
sudo apt-get install python3-rpi.gpioCode: Select all
#!/usr/bin/env python3
import RPi.GPIO as GPIO
print(GPIO.VERSION)Code: Select all
chmod 744 testing+RPI+P3.pyCode: Select all
./testing+RPI+P3.pyCode: Select all
sudo apt-get purge python3*