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, containing (with your correct full python path):
sudo /usr/bin/python "$@"
Be sure to make the script executable:
chmod +x
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 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:

Enjoy it!


Popular posts from this blog

Fix "Set scan parameters failed: Input/output error" on Ubuntu 16.04

from: can't read /var/mail/ in Python scripts

SNMP + Telegraf + InfluxDB