How to run / debug programs with super user privileges

What's the easiest way to run (and debug) a script/program from PyCharm with super user privleges (i.e. sudo)? FYI, I don't want to run the IDE as root.

TIA.

8 comments

Hello Justin,

You can create a shell script that would do 'sudo python " and

specify it as a Python interpreter in Settings | Python Interpreters.

What's the easiest way to run (and debug) a script/program from

PyCharm with super user privleges (i.e. sudo)? FYI, I don't want to

run the IDE as root.

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

That was the first thing I tried and I get the follwoing error:

The selected file is not a valid home for Python SDK

0

Hello Justin,

To make PyCharm recognize it, the name of the script should start with "python".

That was the first thing I tried and I get the follwoing error:

The selected file is not a valid home for Python SDK

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

So, that allows me to execute python via sudo. However, it appears that debugging is not an option as the Python script runs with no regards for breakpoints etc.

Oh, and thanks for the help. :-)

0

I am looking to do the same as the original poster. I have setup a .sh script file and added that as a python environment in the settings. However, when I run my code I get: sudo: no tty present and no askpass program specified. I am new to python and am trying to run simple web.py application which starts a CherryPy/3.1.2 WSGI Server. Via the console I start it with: sudo python service.py 85 (port 85) Any help is greately appreciated.

Would love to see this be part of the Run/Debug Configurations settings.

Awesome product by the way.

0

I will reply to my own post. You don't need to run it as sudo if you use high port numbers. I am now using 8089 and it works like a charm.

0

Are there any news on how to remote debug a python script with PyCharm?

 

The issue i'm facing is that I have to run the script as a specific user (through sudo su - user) - I don't have the option of creating the SSH session directly with the user that is supposed to run the script.

2

How would i go about doing this if i have a remote python interp. I have a raspberry pi robot setup and want to use pycharm to develop for it but python programs on the pi need sudo privileges to access the gpio pins.

i am assuming you would have a file called python-sudo.sh

but i am not sure what to put in it

 

cheers

0

Please sign in to leave a comment.