無法為 Python 程式取得可用的桌面啟動器

無法為 Python 程式取得可用的桌面啟動器

我正在建立一個全新的 Debian 軟體包,cpconverter來自A simple utility to change the code page of plain text based filesGoogle Code 中發布的源代碼。

一切都很順利。但是我無法獲得可用的啟動板啟動器。

python 檔案cpConverter.py儲存在資料夾中/usr/share/cpconverter/cpconverter/

我有一個Shell Script名為cpconverterin 的資料夾/usr/bin/,內容如下:

#!/bin/sh

python /usr/share/cpconverter/cpconverter/cpConverter.py

桌面啟動器cpconverter.desktop很簡單

[Desktop Entry]
Version=0.5
Encoding=UTF-8
Name=Code Page Converter
Name[en_US]=Code Page Converter
Comment=A simple utility to change the code page of plain text based files
Type=Application
Exec=/usr/bin/cpconverter
Icon=cpconverter
Terminal=false
StartupNotify=true
Categories=Utility;

然而它無法啟動。

我確實透過啟動它來檢查安裝的是否cpConverter.py正常工作:

$ python /usr/share/cpconverter/cpconverter/cpConverter.py

然後該程式在某些場合啟動。單擊啟動器後,它通常不再起作用。

cpConverter.py然而,包的建構結構中的文件始終有效,例如

$ python cpconverter-0.5/debian/cpconverter/usr/share/cpconverter/cpconverter/cpConverter.py

我嘗試從終端機輸入相同的命令列,然後遇到各種聞所未聞的錯誤(至少對我來說):

$ cpconverter
/usr/bin/cpconverter: 3: /usr/bin/cpconverter: pyhton: not found
$ 
$ pyhton /usr/share/cpconverter/cpconverter/cpConverter.py
No command 'pyhton' found, did you mean:
 Command 'python' from package 'python-minimal' (main)
pyhton: command not found
$

然後我嘗試為包舉一個工作範例convertall,以供其Shell Script使用:

#!/bin/sh

exec /usr/bin/python3 /usr/share/convertall/convertall.py "$@"

從終端我可以成功啟動它:

$ python3 /usr/share/convertall/convertall.py "$@"

然後我修改Shell Script為:

exec /usr/bin/python2 /usr/share/cpconverter/cpConverter.py "$@"

結果仍然是桌面啟動器無法工作......一些沙漏,什麼都沒有。然而,這 3 個命令列中的任何一個總是啟動程式:

$ python2 /usr/share/cpconverter/cpconverter/cpConverter.py "$@"
$ /usr/bin/cpconverter
$ cpconverter

的存取權限是cpconverter.desktop標準的:

$ ls -l /usr/share/applications/clipgrab.desktop
-rw-r--r-- 1 root root 626 Dec  9  2014 /usr/share/applications/clipgrab.desktop

那麼為什麼桌面啟動器無法啟動該程式呢?我的桌面啟動器出了什麼問題? [參見上面]

答案1

我不確定這是否真的有必要,但是當我製作 bash 腳本時,我使用此命令“bash $$$$$$$.sh”啟動了該腳本。我提到這一點的唯一原因是 .py 副檔名不在桌面啟動器中的腳本名稱上。可能沒什麼,值得一看和嘗試。克雷格

答案2

好吧,正如我在評論中所說,Dash Script/usr/bin/目錄運行就像桌面啟動器正在執行的那樣,失敗並出現以下 Python 錯誤:

/usr/bin$ cpconverter
Traceback (most recent call last):
  File "/usr/share/cpconverter/cpconverter/cpConverter.py", line 342, in <module>
    app = cpConverter()
  File "/usr/share/cpconverter/cpconverter/cpConverter.py", line 74, in __init__
    builder.add_from_file("./gui/gui.xml")
glib.GError: Failed to open file './gui/gui.xml': No such file or directory
$ 

在主資料夾或(coCPnverter.py 檔案所在的位置)cpconverter中其他位置的提示下執行時會成功。/usr/share/cpconverter/cpconverter

那麼很明顯,罪魁禍首就是文件./中的那個人cpConverter.py

我只是創建了一個補丁allow-launch-from-usr-bin-script.patch來放置絕對路徑(一旦打包)而不是相對路徑:

builder.add_from_file("/usr/share/cpconverter/cpconverter/gui/gui.xml")

這解釋並解決了這個問題。

相關內容