No output when using PyCharm with sudo python script

I have the following problem:
I am using PyCharm 4.5.1 on raspberry Pi 2 with python 3.2.3 and I need to access files and modules that require root privileges.
To get root privileges I configured PyCharm to use this script as a python interpreter:

python-sudo.sh:
!#/bin/bash
sudo /usr/bin/python3 "$@"

This works but there is one problem. Any output (print, exceptions,...) produced by the program while it is running will not display in the PyCharm Run output window at the bottom.
Only after the program ends, all it's output will appear.

Does anyone have any idea how to fix this?
3 comments
Comment actions Permalink
Could you please Run Python console (Tools| Python Console) and check result of the following code:

>>> import os
>>> os.environ['PYTHONUNBUFFERED']
prettyPrint();
0
Comment actions Permalink
The output of this code is '1'.
0
Comment actions Permalink
Problem solved by adding -u option for python to the sudo script.

python-sudo.sh:
!#/bin/bash
sudo /usr/bin/python3 -u "$@"
0

Please sign in to leave a comment.