When you run a command with sudo, by default, the system will ask for a password. To avoid this, you will have to change the python interpreter used by PyCharm from default to a custom interpreter. Don't worry, you don't have to build a new interpreter, you will just have to create an intermediate. The solution to solve this is as follows:
First, open a terminal and run this command:
$ sudo visudo -f /etc/sudoers.d/python
Then enter the following line in this file (replace <username><hostname> with the username and hostname of your system respectively):
<username> <hostname> = (root) NOPASSWD: <path/to/python>
Replace <path/to/python> with the path where Python is installed (usually /usr/bin/python) and save this file.
Now you will have to create a sudo shell script. Run the following command in the terminal:
$ nano python-sudo.sh
and enter the following lines in it:
sudo /usr/bin/python "$@"
Save and exit and change the permission of this file:
$ chmod +x python-sudo.sh
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. Now you won't be asked for passwords.