Python Forum

Full Version: Python IDLE 3.6.2 on WIn7 vs Pyhton 3 IDLE raspberry
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi! all.
First question:
I have a small starter program that bugs me. I took this one on the net
and work well in Raspberry Pi3 Stretch & Python 2.7.13, in command line
like: python test01.py , it print too, the version of running GPIO = 0.6.3
But when I try it with Python 3.6.2 in Raspberry or on the Python 3.6.2 on Windows 7
it give me this on both:
Traceback (most recent call last):
File "test01.py", line 1, in <module>
import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

What can I do to be able to make it work.

Second question:
I build the Python 3.6.2 on rapsberry pi3 "Raspbian GNU/Linux 9 (stretch)"
using this internet address as a guide:
"bohdan-danishevsky.blogspot.ca/2017/01/building-python-360-on-raspberry-pi-3.html"
Everything works well when I type python3.6 , But If I type python, then it's 2.7.13.

What ca I do to have version 3.6.2 when I type python.

Thanks Smile
--------------------------------------------------

import RPi.GPIO as GPIO
import time

LedPin = 11 # pin11

def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
GPIO.setup(LedPin, GPIO.OUT) # Set LedPin's mode is output
GPIO.output(LedPin, GPIO.HIGH) # Set LedPin high(+3.3V) to turn on led

def blink():
while True:
GPIO.output(LedPin, GPIO.HIGH) # led on
time.sleep(1)
GPIO.output(LedPin, GPIO.LOW) # led off
time.sleep(1)

def destroy():
GPIO.output(LedPin, GPIO.LOW) # led off
GPIO.cleanup() # Release resource

if __name__ == '__main__': # Program start from here
setup()
try:
blink()
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.

destroy()
you will need to install the python 3 RPi.GPIO package.
do you have pip on the pi?
if so, the command will be:
pip3 install RPi.GPIO 
To answer your second question python2.7 is installed on the raspberry pi by default.
Typing:

which python

which python3

will return the relative path. You can create a symlink but this is not advisable
as any other software that requires python2.7 will break.

You should be able to run python 3.6 just by typing
python3

On debian 8 this defaults to python3.4.3, I've not upgraded to DEbian 9 yet.
Quote:Everything works well when I type python3.6 , But If I type python, then it's 2.7.13
 the paths are messed up. Don't know how to fix this in firmware.
you may have to specifically use python
python3.6 myscript.py
Hey! thanks
I thought that since it appears to be 0.6.3 on the default Python 2.7.13,
it was the same module used bu the Python 3.6.2. My mistake.
I used "sudo pip3 install RPi.GPIO" and everything works properly.
Good!