Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Python on RPiOS

Mon Jun 22, 2020 8:14 pm

Can you install Python on RPiOS. If this is possible, which version do you need to download.

python.org/downloads/

User avatar
DougieLawson
Posts: 40166
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Python on RPiOS

Mon Jun 22, 2020 8:16 pm

All versions of Raspbian (since Wheezy) and RaspiOS already include an appropriate (and current when built) version of python2 and python3.

What are you attempting to do?
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Mon Jun 22, 2020 8:26 pm

DougieLawson wrote:
Mon Jun 22, 2020 8:16 pm
All versions of Raspbian (since Wheezy) and RaspiOS already include an appropriate (and current when built) version of python2 and python3.

What are you attempting to do?
I have downloaded a couple of books on learning Python and how to write some basic programs.

How do you start Python on RPiOS.

User avatar
DougieLawson
Posts: 40166
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Python on RPiOS

Mon Jun 22, 2020 8:30 pm

There's an interactive development evironment (IDE) called Thonny in the menu. That's your best starting point for python.

Otherwise open an LXTerminal window, use nano /home/pi/mypythonprogram.py to edit your code then use python3 /home/pi/mypythonprogram.py and it will run. Trust me, Thonny is easier for beginners.

https://magpi.raspberrypi.org/articles/thonny
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

pfletch101
Posts: 630
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: Python on RPiOS

Mon Jun 22, 2020 8:35 pm

Raspberry Pi Micro wrote:
Mon Jun 22, 2020 8:26 pm
I have downloaded a couple of books on learning Python and how to write some basic programs.

How do you start Python on RPiOS.
Enter

Code: Select all

python
at the system command line for Python 2, or

Code: Select all

python3
at the system command line for Python 3. These will give you the relevant version of python's command line.

If you like (or your book uses) IDEs, Thonny and Geany are part of the non-lite packages and can be found on the 'Programming' tab of the main menu.

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Tue Jun 30, 2020 2:09 pm

pfletch101 wrote:
Mon Jun 22, 2020 8:35 pm
Raspberry Pi Micro wrote:
Mon Jun 22, 2020 8:26 pm
I have downloaded a couple of books on learning Python and how to write some basic programs.

How do you start Python on RPiOS.
Enter

Code: Select all

python
at the system command line for Python 2, or

Code: Select all

python3
at the system command line for Python 3. These will give you the relevant version of python's command line.

If you like (or your book uses) IDEs, Thonny and Geany are part of the non-lite packages and can be found on the 'Programming' tab of the main menu.
Finally looks like I now have Python3 installed. I start Terminal and then type python 3 and then the following information is displayed.

Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "licence" for more information.
>>>>

There are many pages of python code in many of the Pi Magazines like in the screenshot below, In this example how do I start to type in some of this code by starting python3, or would I need to start using Thorny Python IDE. But still not 100% sure how to start entering code using python3.
Image

I have also downloaded MagPi Issue 53 which may also be a starting point as well.
Image

The MagPi Essentials Make Games with Python, does interest me a lot, as I would also like to convert some simple BBC Micro games to python once I have a good understanding.
Image

The graphics in this game are simple enough, with the design of the screens.
Image

Any help here will be most welcome.

User avatar
rpiMike
Posts: 1530
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Python on RPiOS

Tue Jun 30, 2020 2:21 pm

As mentioned use Thonny.

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Tue Jun 30, 2020 2:33 pm

rpiMike wrote:
Tue Jun 30, 2020 2:21 pm
As mentioned use Thonny.
Ok thank you, is this the same or slightly different version of python.

From the Thorny View menu, what should I have selected or shown.

User avatar
rpiMike
Posts: 1530
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Python on RPiOS

Tue Jun 30, 2020 2:36 pm

Thonny uses Python3

klricks
Posts: 7287
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Python on RPiOS

Tue Jun 30, 2020 3:33 pm

Raspberry Pi Micro wrote:
Tue Jun 30, 2020 2:33 pm
rpiMike wrote:
Tue Jun 30, 2020 2:21 pm
As mentioned use Thonny.
Ok thank you, is this the same or slightly different version of python.

From the Thorny View menu, what should I have selected or shown.
The Thonny IDE is not itself Python.....It is a tool to help you write and debug your Python code. As mentioned any text editor such as nano or mousepad could be used to write Python code, but an IDE has a lot more features to help you write and debug your code.

Once your code is written and working, in most cases, the IDE is no longer needed and you just run your code from the command line or desktop like any other app or command.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

User avatar
jahboater
Posts: 6274
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

Re: Python on RPiOS

Tue Jun 30, 2020 4:50 pm

Firstly please forget mentions of Python2. It was officially end-of-life six months ago.
Python3 is the only version of Python you need think about, and henceforth "Python" refers to Python3.

Python is a programming language much like any other. You write your program in an english like language that a human can understand, and it gets translated into a different language that only the computer can understand.
The program you write is just a simple text file that you can produce with any text editor. It is called "source" code.
You give the program to the Python translator (called an interpreter) which reads the english like text in, converts it into the machine language, and executes it. The interpreter is a computer program called "python3".

Python is slightly unusual in that you can enter an interactive mode (just by typing "python3") where you may type in commands and expressions directly and it will translate and execute them immediately. Makes a nifty calculator ....

Code: Select all

 $ python3
Python 3.7.2 (default, Jan  9 2019, 15:51:37) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2 + 2
4
>>> print("Hello world!")
Hello world!
>>> 
Normally however, you would create a text file typically suffixed with ".py" such as "hello.py" with an editor. The file contains your program.
Then you type "python3 hello.py" and it will run your program. (You can avoid typing the initial python3 all the time).

As noted above, you can use literaly any text editor you like, there are many to choose from. Nano on the Pi is fine and simple to use.

There are also various IDE's where you edit your program, run it, debug it etc all in the same place (that's why they are called Integrated Development Environments - IDE). The editors within these IDE's may offer better facilities for Python source such as highlighting keywords in different colours etc.
Pi4 8GB running PIOS64 Lite

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Tue Jun 30, 2020 5:00 pm

klricks wrote:
Tue Jun 30, 2020 3:33 pm
Raspberry Pi Micro wrote:
Tue Jun 30, 2020 2:33 pm
rpiMike wrote:
Tue Jun 30, 2020 2:21 pm
As mentioned use Thonny.
Ok thank you, is this the same or slightly different version of python.

From the Thorny View menu, what should I have selected or shown.
The Thonny IDE is not itself Python.....It is a tool to help you write and debug your Python code. As mentioned any text editor such as nano or mousepad could be used to write Python code, but an IDE has a lot more features to help you write and debug your code.

Once your code is written and working, in most cases, the IDE is no longer needed and you just run your code from the command line or desktop like any other app or command.
Thank you. Think I will start with Thorny Python IDE, from the menu at the top, you select View, this it gives you a number of views options, what should I best select here to start with.

Assistance
Exception
Files
Heap
Help
Notes
Object Inspector
Outline
Program Tree
Shell
Stack
Variables

Program Arguments
Plotter

Increase Font Size
Decrease Font Size

Focus Editor
Focus Shell

Only options I have selected are;

Shell
Varables

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Tue Jun 30, 2020 6:45 pm

What options are there for taking a screenshot on RPiOS, if it's the whole screen or just an active window.

On Mac OS it's CMD + SHIFT + 3 and CMD + SHIFT + 4

klricks
Posts: 7287
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Python on RPiOS

Tue Jun 30, 2020 7:07 pm

Raspberry Pi Micro wrote:
Tue Jun 30, 2020 6:45 pm
What options are there for taking a screenshot on RPiOS, if it's the whole screen or just an active window.

On Mac OS it's CMD + SHIFT + 3 and CMD + SHIFT + 4
Pressing the [Print Screen] key will capture the entire screen and save a .png image in the current directory.
For more options you can run scrot from the command line.
For details see:

Code: Select all

scrot -h
and

Code: Select all

man scrot
For me I connect remotely with VNC and do the [Alt] [Print Screen] from Windows 10. You should be able to do something similar with the MAC.
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Raspberry Pi Micro
Posts: 102
Joined: Mon Jun 15, 2020 7:59 am

Re: Python on RPiOS

Tue Jun 30, 2020 7:41 pm

klricks wrote:
Tue Jun 30, 2020 7:07 pm
For me I connect remotely with VNC and do the [Alt] [Print Screen] from Windows 10. You should be able to do something similar with the MAC.
How do you connect remotely with VNC.

klricks
Posts: 7287
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Python on RPiOS

Tue Jun 30, 2020 9:07 pm

Raspberry Pi Micro wrote:
Tue Jun 30, 2020 7:41 pm
klricks wrote:
Tue Jun 30, 2020 7:07 pm
For me I connect remotely with VNC and do the [Alt] [Print Screen] from Windows 10. You should be able to do something similar with the MAC.
How do you connect remotely with VNC.
Documented on RPi website:
https://www.raspberrypi.org/documentati ... /README.md
Unless specified otherwise my response is based on the latest and fully updated RPiOS Buster w/ Desktop OS.

Return to “Beginners”