Running Pycharm as root from launcher

后端 未结 6 2120
小鲜肉
小鲜肉 2021-02-19 07:04

How is it possible to run Pycharm from the launcher with root privileges?

I can do that from the terminal window, with sudo ./pycharm.sh, but I\'d like to d

6条回答
  •  一个人的身影
    2021-02-19 07:57

    I had the need to run a script from PyCharm as root like the OP, but the accepted answer didn't work for me because 1.) I had installed PyCharm via flatpak and 2.) The gksu command isn't available on newer versions of Ubuntu and Mint.

    I couldn't find a way to make things work consistently with the flatpak install so I uninstalled the PyCharm flatpak and then reinstalled PyCharm the "normal" way. The accepted answer relies on the gksu command which is not available on my OS (Mint 19.2). Thankfully pkexec is a suitable alternative and was already available on my system. I then updated my launcher file (~/.local/share/applications/PyCharm.desktop) as follows. The important bit is the Exec line:

    [Desktop Entry]
    Name=PyCharm
    Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /opt/pycharm-community-2019.2.2/bin/pycharm.sh
    Comment=PyCharm
    Terminal=false
    Icon=/opt/pycharm-community-2019.2.2/bin/pycharm.png
    Type=Application
    

    The pkexec command will cause a popup to appear prompting you for your password each time you launch PyCharm via the .desktop file.

提交回复
热议问题