PyCharm incorrectly identifying python version when creating an existing interpreter
I am attempting to create a local interpreter entry in a project so that when PyCharm runs/debugs the code, it runs as root. I am following the instructions here: https://esmithy.net/2015/05/05/rundebug-as-root-in-pycharm/ The idea is to create a bash shell script that sudo executes the target python interpreter. The steps are: create the file /etc/sudoers.d/python with the following content:
<user> <machine>=(root)NOPASSWD:<path to python interpreter>. Then create a bash shell script called python-sudo.sh with the following content:
#!/bin/bash
sudo <path to python interpreter> "$@"
Put this file in some convenient location. For my example it is placed in: /opt/saltstack/salt/bin/
However, when I attempt to create the local interpreter entry (using the “Existing” option, I get an error “Invalid Python SDK” and the interpreter version is 3.13, whereas the python I reference is 3.10. This is seen in the 3 screenshots attached to this message (ID: 2024_09_10_wH4UYAUnNrhZ41uJ54pZun). The complete information is captured in this gist: https://gist.github.com/dnessett/ce873396bc5f0a175eb58ba86055ecd2.
请先登录再写评论。
I've tried this setup, and it seems to work as expected. Could you please share the contents of your sh script?
Thanks for the reply.
The contents are in the gist file referenced with the link. However, for the record, here is the sh script:
#!/bin/bash
sudo /opt/saltstack/salt/bin/python3.10 "$@"
I see the image doesn't show the complete contents of /opt/saltstack/salt/bin, where python3.10 resides. Here is the listing of that directory:
dnessett@MOLS-T-0:~$ cd /opt/saltstack/salt/bin
dnessett@MOLS-T-0:/opt/saltstack/salt/bin$ ls -al
total 3380
drwxr-xr-x 2 root root 4096 Sep 10 11:21 .
drwxr-xr-x 7 root root 4096 Aug 2 15:22 ..
-rwxr-xr-x 1 root root 325 Jul 29 01:42 calc-prorate
-rwxr-xr-x 1 root root 287 Jul 29 01:42 cheroot
-rwxr-xr-x 1 root root 291 Jul 29 01:42 cherryd
-rwxr-xr-x 1 root root 282 Jul 29 01:42 distro
-rwxr-xr-x 1 root root 1742 Jul 29 01:42 jp.py
-rwxr-xr-x 1 root root 321 Jul 29 01:42 normalizer
-rwxr-xr-x 1 root root 298 Jul 29 01:42 pip
-rwxr-xr-x 1 root root 298 Jul 29 01:42 pip3
-rwxr-xr-x 1 root root 298 Jul 29 01:42 pip3.10
lrwxrwxrwx 1 root root 10 Jul 29 01:42 python3 -> python3.10
-rwxr-xr-x 1 root root 3401008 Jul 29 01:42 python3.10
-rwxr-xr-x 1 root root 3535 Jul 29 01:42 python3.10-config
lrwxrwxrwx 1 root root 17 Jul 29 01:42 python3-config -> python3.10-config
-rwxr-xr-x 1 root root 58 Sep 10 11:16 python-sudo.sh
-rwxr-xr-x 1 root root 291 Jul 29 01:42 relenv
Note the existence of python3.10.
Once, again thanks for your reply.
The idea is the IDE would be started by a user who has sudo privileges to start python. This is shown on line 2 of https://gist.github.com/dnessett/ce873396bc5f0a175eb58ba86055ecd2 . When python is executed by that user, using the script python-sudo, python runs as root.
In answer to your 2nd question, yes python3.10 works as expected:
dnessett@MOLS-T-0:~$ /opt/saltstack/salt/bin/python3.10
Python 3.10.14 (main, Jun 26 2024, 11:44:37) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
However, the problem is PyCharm (again as shown by https://gist.github.com/dnessett/ce873396bc5f0a175eb58ba86055ecd2 ) is incorrectly identifying the shell script as python3.13, rather than python3.10. This is then determined by the PyCharm application as an invalid Python SDK.
I left a message 2 days ago and it is still not approved. Why not?
I'm going to repeat the answer I gave to Danill Bogdnov's question two days ago:
Once, again thanks for your reply.
The idea is the IDE would be started by a user who has sudo privileges to start python. This is shown on line 2 of https://gist.github.com/dnessett/ce873396bc5f0a175eb58ba86055ecd2 . When python is executed by that user, using the script python-sudo, python runs as root.
In answer to your 2nd question, yes python3.10 works as expected:
dnessett@MOLS-T-0:~$ /opt/saltstack/salt/bin/python3.10
Python 3.10.14 (main, Jun 26 2024, 11:44:37) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
However, the problem is PyCharm (again as shown by https://gist.github.com/dnessett/ce873396bc5f0a175eb58ba86055ecd2 ) is incorrectly identifying the shell script as python3.13, rather than python3.10. This is then determined by the PyCharm application as an invalid Python SDK.
I'm giving up on PyCharm Community, since: 1) for some reason my answer to Daniil Bogdanov's last question (answered on Thursday at 9:24) is not displaying because it is waiting for “approval”; and 2) I tried to report this problem as a bug, but there doesn't seem to be a way to report bugs for PyCharm Community. In other words, PyCharm Community is not a real supported product.
Sorry for the late reply.
I see that chmod +x is missing in the gist, but the script has executable permissions under the ls command. Could you please double-check that?
Hi Daniil,
I appreciate your help with this issue. However, as I mention in a post above, I have given up on PyCharm Community and moved on to Eclipse/PyDev for the reasons given in that post. Thanks for the help you gave me and I wish you the best of luck in the future..