How to run root python scripts on Pycharm

Mininet needs root privileges ti run. If you run a python mininet script on Pycharm you will see the following message:

*** Mininet must run as root.
















To enable root privileges, you need create a new interpreter as follows:

sudo visudo -f /etc/sudoers.d/python
Add the following information:
<user> <host> = (root) NOPASSWD: <full path to python>
For example:
boettcher boettcher-server = (root) NOPASSWD: /usr/bin/python
Create a script called python-sudo.sh, containing (with your correct full python path):
#!/bin/bash
sudo /usr/bin/python "$@"
Be sure to make the script executable:
chmod +x python-sudo.sh
To change your actual interpreter for this new one, in PyCharm, go to File > Settings > Project Interpreter. Click the gear icon by the current Project Interpreter drop-down, and choose “More…”.








Then click the green plus icon to add a new interpreter (Add Local). 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.

Thanks to Eric Smith for the solution in his blog: http://esmithy.net/2015/05/05/rundebug-as-root-in-pycharm/

Enjoy it!

Comments

Popular posts from this blog

Exception: Could not find a default OpenFlow controller in Mininet

How to fix Android when developer options are not available for this user

Webcam streaming throught VLC with YUY2 compatibility