I want to make a file executable, but I don't know how to do that and have the idle prompt appear afterward. Is the best way to just open idle and then import the file? I'm using python3 on raspbian jessie. Can you add flags like -i when you make the file executable? Please help.

Update I found that adding the -i flag in the beginning of the file works.

  • What does pause the script mean? If you write an executable you tend to keep the script running and you can close or kill it. And yes you are add flags when making files executable
    – Shan-Desai
    Jul 27, 2016 at 21:51
  • Pause meaning not exiting after running; stopping and showing the python prompt. And I mean a flag like when you run a python file with python: python3 -i blahblah.py.
    – jath03
    Jul 27, 2016 at 22:03

2 Answers 2

  1. Keep all your executable files in a folder, I usually keep it in /home/pi/. Your folder can be called for example exec

    mkdir exec
  2. move your Python3 script into this folder:

    mv myScript.py ~/exec/
  3. In your myScript.py add the shebang line on the top-most part of script

    $ nano myScript.py
    ## add this line on top of file

CTRL+O then press Enter and in the end CTRL+X

  1. give executable rights to your file:

    $ chmod +x myScript.py

Additional : you can also remove the .py from the file and keep it just myScript

    mv myScript.py myScript

You have your script as an executable you can trigger it by doing a simple


Pausing Scripts

I think this is inherent to the script you have written, you can use time.sleep in your script to pause the working and do something in the meantime for e.g. print something or do nothing.

Adding Arguments

You can use configParser module in Python to give arguments to your script

Your executable will now run as:

./myScript -arg1 -arg2


Python3 ConfigParser

time.sleep() for Pausing Python scripts


Parse Flags to a Python Executable

  • Thanks, but I already knew how to make it executable. I was trying to make running ./file.py the same as running python3 *-i* file.py
    – jath03
    Jul 27, 2016 at 23:37

I am running python 3.7.3 on a Raspberry Pi 3. I found that I needed to change the line at the top of the file from




in order to get it to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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