Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in pyCharm with sudo privileges?

Tags:

I've tested code that requires root access in pyCharm by running sudo pycharm.sh but this is not the way I would recommend of doing so.

I know it's possible to debug with sudo privileges by running the python interpreter as sudo in pyCharm but how do we do this?

like image 731
Dayan Avatar asked Jan 13 '13 00:01

Dayan


People also ask

How do I give sudo permission to PyCharm?

Now go to PyCharm, go to File > Settings > Project Interpreter. Click on the settings icon and click on the green plus icon to add interpreter. Browse to the directory where you have saved the python-sudo.sh and select it. Save changes and exit.

How do I run a sudo privilege in python?

From the terminal instead of doing python yourProgram.py , do sudo python yourProgram.py . It will ask for your password so type it and it should run.

How do I run a program as root in PyCharm?

Use the script as your Python interpreter Click the gear icon by the current Project Interpreter drop-down, and choose "Add…". Then choose Existing environment. Browse to python-sudo.sh and select it, and set it as the interpreter for the project. Now when you run or debug, the code will run as root.


2 Answers

Create a shell script that does "sudo python" and forwards the arguments, and configure that script as a Python interpreter in PyCharm.

Name of this shell script should start with python (source: http://forum.jetbrains.com/message/PyCharm-424-3).

like image 189
yole Avatar answered Sep 17 '22 19:09

yole


In PyCharm new version, it has a configure to run Python interpreter in root, no need workaround. See picture below. Check to checkbox: Execute code using this interpreter with root privileges via sudo

enter image description here

like image 35
phapli Avatar answered Sep 19 '22 19:09

phapli