Derp1234
Posts: 3
Joined: Thu May 12, 2016 1:50 pm

Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 2:00 pm

I tried looking at many different websites and tutorials and I still don't know where I need to put the Python code to run it. Is there a special upload process? Do I need to put the program on the Micro SD card? I have Raspberry Pi 3 Model B. (I don't know if it is B or B+)

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 2:46 pm

in the menu under programming on your raspbian install is the "idle3" python programming ide, click this and it will pop up a screen with the python version and a command prompt, from here you click file, new . this will popup a new window on the screen, this is where you type and save your scripts.
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 3:05 pm

Derp1234 wrote:I tried looking at many different websites and tutorials and I still don't know where I need to put the Python code to run it. Is there a special upload process? Do I need to put the program on the Micro SD card? I have Raspberry Pi 3 Model B. (I don't know if it is B or B+)
There is no PI 3B+

... the Raspberry PI is a gnu+linux system based on the debian distribution and tuned for the Arm processor. As such, you may place your Python codes anywhere you like (from a Python directory in your PYTHONPATH to your ~/bin/ folder, to /usr/local/bin/ folder; literally anywhere you like) depending on permissions, who will be using it, under what conditions, and at what times. Its a lot like a box Legos; infinite configurability and limitless flexibility.

This is quite unlike the Arduino, for instance, which must have its codes uploaded to a single place (with special software) so that it can be run by its special boot-loader. The Raspberry PI is a computer system... place your codes where you like!
marcus
:ugeek:

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 3:07 pm

If you have a Raspberry Pi 3 then it's a "B" model. There is no RPI3 B+, or at least not yet.

You can put a script just about anywhere and run it, but by convention they are usually put in "/usr/bin/", or I create a directory named "scripts" where I put them, so all my scripts are together in the same place. The path to my scripts would be "/home/pi/scripts/". Makes it much easier when doing a new setup, I just copy my "scripts" folder over to the new setup and I've got everything there.

You can create the script right on the Pi using the Leafpad text editor, or if it's a Python script you can use IDLE, both are already installed on the RPI. Or you can open LXTerminal on the Pi and use "nano", "vi", or some other text editor to create the file. If you're using SSH and connecting to the PI with Putty from your PC you can use the "nano" editor in the Putty terminal, but you gain the advantage of being able to copy/paste text from your PC right into Putty which makes things easier.

Or you could share a folder on the PC, create the file there, then just copy it to the RPi. Or vice versa, and share a folder on the RPi using SAMBA and access it from your PC to copy the files over.

There are a lot of different ways to do it, and everybody has their favorite method, those are just a few. As you progress along you'll come up with your own favorite way to do it.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 3:18 pm

Derp1234 wrote:I tried looking at many different websites and tutorials and I still don't know where I need to put the Python code to run it. Is there a special upload process? Do I need to put the program on the Micro SD card? I have Raspberry Pi 3 Model B. (I don't know if it is B or B+)
Welcome to the Raspberry Pi - things will become clearer when you start to use it.

I think your internal mental picture of the RPi is of a fairly simple board to which you upload a single program when you want to run it? Like an Arduino, Crumble, CodeBug or microBit, if you are familiar with any of those? The RPi can be run in that way: it is a special use of the RPi known here as 'Bare Metal'. You would not be able to use python to program the board in this way.

But the RPi is more powerful and more flexible than a simple one board controller - it can run a full-fledged graphical operating system. In that respect it has far more in common with a 'Windows' or 'Mac' desktop/laptop machine - although the specific details of the user interface are different.

So you can upload code to it if you wish, or you can edit code - python scripts - directly on the RPi as explained above.

The only form of storage associated directly with an RPi is its microSD card, so all your work will be stored there.

There are many beginners tutorials and resources available directly from the Raspberry Pi Foundation here: https://www.raspberrypi.org/resources/

Your RPi is a Raspberry Pi 3 Model B - there is no Raspberry Pi 3 Model B+ announced as of the time this reply was written.

[Postscript: reply posted just after the one from JimmyN, so some content is duplicated.]

Derp1234
Posts: 3
Joined: Thu May 12, 2016 1:50 pm

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 5:05 pm

OK, thanks! Also, I'm wondering if when I run code if it will automatically run on the Raspberry Pi. Like if I make code to use a temperature sensor would it use the temperature plugin automatically even if I unplugged the HDMI from the display?

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 5:12 pm

Derp1234 wrote:OK, thanks! Also, I'm wondering if when I run code if it will automatically run on the Raspberry Pi. Like if I make code to use a temperature sensor would it use the temperature plugin automatically even if I unplugged the HDMI from the display?
You may run your PI headless... no display, keyboard, nor mouse. You may configure it to run anything you like (within reason) automatically on bootup... but you need to configure it (setup and maintain yourself).

Also, you may control your automated headless PI from remote (using your phone, a remote terminal over ssh, or even a full desktop using VNC over a secure ssh tunnel! Its all up to you, how much you want to study, and how hard you're willing to work.
marcus
:ugeek:

Derp1234
Posts: 3
Joined: Thu May 12, 2016 1:50 pm

Re: Where Do I Put My Python Code To Run It On Raspberry Pi?

Thu May 12, 2016 6:46 pm

Thanks for solving my questions. Iv'e been struggling on these for days! I hope this can help other people too! :D

Return to “Beginners”