This can be accomplished by creating a shell script which would run your script through ProxyChains and then using this script as an interpreter in PyCharm.
First, create a shell script named python
in your project directory (let's say it's located at ~/MyProject
):
#!/bin/sh
proxychains4 /usr/bin/python3 "$@"
$@
is used to pass all the arguments (specifically, path to your main script) through this script to the actual Python interpreter (/usr/bin/python3
).
Make this script executable:
chmod +x ~/MyProject/python
Now we can add this script as an interpreter in PyCharm.
If you're not using a virtual environment for this project, you can just add a new system interpreter and pick the created python
shell script (~/MyProject/python
) as the executable. Then add a new configuration using this new interpreter and path to your main script.
If you need a virtual environment for this, create a new virtual environment, specify its location and path to your default python interpreter (say, /usr/bin/python3
), install all the necessary dependencies inside it and then once again go to Preferences -> Python Interpreter -> Show all
, select your newly created virtual environment and change the "interpreter path" field to the shell script path (~/MyProject/python
).
And one more step. Since PyCharm's debugger uses a built-in local server, you need to exclude connection to it in proxychains.conf
:
localnet 127.0.0.1/255.255.255.255
Voilà!
[proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.17/lib/libproxychains4.dylib
[proxychains] DLL init: proxychains-ng 4.17
[proxychains] DLL init: proxychains-ng 4.17
Connected to pydev debugger (build 233.13763.11)
[proxychains] Strict chain ... 171.244.140.160:3991 ... api.ipify.org:443 ... OK
{'ip': '171.244.140.160'}
