I am trying to get a python code to run on boot on the raspberry pi. I added the following line to the .bashrc file at the end of the file:

sudo python3 /home/pi/code.py

The pi uses python2 to run the code instead of python3. Why is this happening and how can I make it run python3?


  • Does this answer your question? Python 3 default python – M. Rostami Jan 24 at 19:45
  • 1
    No, I don't want to make python3 my default python version. Thanks though. – user113912 Jan 24 at 20:09
  • What is the added line to .bashrc meant to do? Call the script at shell start? How do you know it is not working? – joan Jan 24 at 21:02
  • 3
    Please show the first line of code.py – bls Jan 24 at 23:46
  • .bashrc will not be executed at boot, so whatever is starting your script at boot time using Python2 it is not the line you're looking at. – Dmitry Grigoryev Jan 27 at 12:21

.bashrc is NOT intended to run scripts.

It is run each time a non-login interactive shell is started and is used to configure the shell.
~/.bashrc: executed by bash(1) for non-login shells.

There are many ways of running scripts, depending on what you are trying to do. See https://raspberrypi.stackexchange.com/a/47537/8697 for an example.

(There are other problems with the script, but as you shouldn't use it for this purpose, not relevant.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.