在 Ubuntu 中重建 PyCharm 启动程序

我通常通过 bin/pycharm.sh安装 pycharm,但是我犯的错误是在下载文件夹中执行 pycharm 目录中的 bash pycharm.sh 同时

后来我将目录移到了 /opt/Pycharm/。这导致每次我尝试使用(正如预期的那样)曾经运行过的统一启动程序(在最初安装 PyCharm 时添加的)都会失败。

我如何重新添加 pycharm.sh作为一个可发布的应用程序从统一启动?我知道 pycharm.sh文件的位置。我试图把它添加到 /usr/bin/,但这不会改变任何东西。

我仍然可以通过 bash /usr/opt/Pycharm/bin/Pycharm.sh发射魅惑术,但是这很乏味。

更新

我已经尝试使用下面的脚本为 pycharm 创建一个新的 .desktop文件:

[Desktop Entry]
Encoding=UTF-8
Name=PyCharm
Exec=/opt/Pycharm-3.0.1/bin/pycharm.sh
Icon=/opt/Pycharm-3.0.1/bin/PyCharm_32.png
Type=Application
Categories=Development;
StartupWMClass=PyCharm

但是,当我试图在 /usr/share/applications/pycharm.desktop中保存文件时,我得到一个“ Unable to save Pycharm.desk”错误。如有任何帮助,我们将不胜感激。

54080 次浏览
sudo vim `which charm`

Now edit the RUN_PATH.

I managed to solve it. The thing is, Pycharm already installs a launcher inside .local/share/applications. Thus, you need to get rid of it before proceeding to create your own. After that, all you have to do is add your own *.desktop file to the applications directory inside usr/share/applications/.

You need to create your .desktop file using sudo and inside the desktop file:

[Desktop Entry]
Encoding=UTF-8
Name=PyCharm
Exec=/opt/pycharm-3.0.1/bin/pycharm.sh
Icon=/opt/pycharm-3.0.1/bin/pyCharm.png  # Changed from pycharm_32.png
Type=Application
Categories=Development;
StartupWMClass=PyCharm

After that is done, you can launch your app properly. Please note that pycharm.sh must also have execution rights.

First start pyCharm from it's bin folder via command line

$ ./pycharm.sh

Then, goto

Tools -> Create Desktop Entry.

It will create a correct Desktop file in the correct place. Afterward you can initiate it from the menu and pin the icon or drag and drop it to the bar. This way, you don't have to deal with .desktop files and mumbo jumbo..

I recently resolved a related issue where, after updating from v2.7 to v3.0.2, my PyCharm launcher was still pointing to the old (and now deleted) PyCharm path.
After attempting all of the (good) advice above, the problem still persisted.
The solution, in my case, was to create a desktop entry for ALL USERS.
[Welcome Screen]->Configure->Create Desktop Entry...
Check the box: "Create entry for all users" and then proceed.

Apparently, in a previous installation I must have installed it in this fashion and was not able to update the launcher for a single account.

In case you just want to update your launcher to point to an updated PyCharm, for me changing 4.0.4 to 4.0.6 in the following worked:

nano /usr/share/applications/jetbrains-pycharm.desktop

When Tools -> Create Desktop Entry does not work:

Create a new file on your desktop (using vi or a similar command) named:
jetbrains-pycharm.desktop

Paste the following inside:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Name=PyCharm
Icon=/opt/pycharm-5.0.1/bin/pycharm.png
Exec="/opt/pycharm-5.0.1/bin/pycharm.sh" %f
Comment=Develop with pleasure!
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-pycharm

Keep in mind to change the path and version number of icon and exec properties above.

Tested on various versions of PyCharm - like a charm ☺

Now the pycharm updated to version 2016.1 and I find the file jetbrains-pycharm.desktop in the path ~/.local/share/applications

then just edit the path for Icon and Exec

In the 2016 version of PyCharm just do following:

  1. Start PyCharm.
  2. From the Tools menu, select "Create Desktop Entry..."
  3. Create entry for "all the users" if required.
  4. Relaunch PyCharm from Launcher.

Ubuntu 16.04 (haven't checked prior versions)

Run pycharm.sh (make sure you use the correct dir and PyCharm version below):

$ ./dir_where_you_placed_it/pycharm-2016.1.4/bin/pycharm.sh

While PyCharm is running, right click its icon on the Launcher and select "lock to Launcher".

Simply type this on your terminal window:

jetbrains-pycharm.desktop

Hope that helps :)

I just wanted to add, I just installed PyCharm Edu for Ubuntu 16.04 LTS today, and the way to create a desktop entry is very easy. When PyCharm Edu opens up, before entering any project, click on configure, and there should be a create Desktop Entry option. Select it, and it will create a PyCharm Edu.desktop file in the following directory:

/usr/local/share/applications

Now traverse to that destination, and click the newly created PyCharm Edu.desktop file to launch PyCharm Edu. After that, you would just need to lock to launcher. It should work.

I know I am very late, but I hope I've helped those of us on Ubuntu 16.04 LTS who are trying to configure a desktop entry for this specific application.

Run $ pycharm-community Right after you will see the icon on the taskbar. Right Click, select Lock on the Taskbar. Somewhat solves the problem.

I guess you didn't check 'Create the entry for all users (requires superuser privileges)' option on Tools -> Create Desktop Entry. You should check it.

You don't have to create something new.

With Ubuntu 16.04, I used the "snap" installer, which doesn't include an easily accessible icon (there's probably one hidden inside the snap image, but it's hard to get at). Instead it shows a grey question mark icon in the launcher instead. Also there doesn't seem to be a Tools > Create Desktop Entry option in version 2017.3.3 as far as I can see - maybe it has been moved somewhere.

So I copied pycharm.png from an earlier non-snap Community installation, saved it somewhere, then created ~/.local/share/applications/jetbrains-pycharm-ce.desktop:

[Desktop Entry]
Version=1.0
Type=Application
Name=PyCharm Community Edition
Icon=/path/to/pycharm.png
Exec="/snap/bin/pycharm-community" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-pycharm-ce

Then when I start PyCharm (from the command line), the launcher item appears with the correct icon, and then I right-click on it and choose "Lock to Launcher", and it now persists.

A downside is that the icon will not be automatically updated with the app, so it might fall out of date.

Simply replaced the Icon=/path/to/pycharm.pngin ~/.local/share/applications/jetbrains-pycharm-ce.desktop from meowsqueak's answer with the correct path when installed from snap.

[Desktop Entry]
Version=1.0
Type=Application
Name=PyCharm Community Edition
Icon=/snap/pycharm-community/current/bin/pycharm.png
Exec="/snap/bin/pycharm-community" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-pycharm-ce

you can always use python for automation may be this will help you a python script that allows u to run pycharm as user or sudoers/root

    import os
from time import sleep
sleep(1)
program = input('which program to run: >')


if program == "pycharm":
os.chdir('#full path to pycharm paste here')
root = input('run as root(y/n): >')
if root == 'y':
print('started ' + program + ' as root')
sleep(0.5)
print('please enter root password to continue:')
os.system('sudo ./pycharm.sh')
elif root == 'n':
print('running ' + program + ' as non root')
os.system('./pycharm.sh')
elif program != 'pycharm':
print('program not found')

I have an LXDE desktop (on Debian Buster) and using PyCharm CE 2020.2.3. Choosing Create Desktop Entry... created nothing on the desktop, no matter whether Create the entry for all users was checked or not.

However, the PyCharm menu entry (under Programming) offers a context menu entry Add to desktop. Clicking this finally made the desktop icon appear.