Python 脚本的桌面启动器在错误的路径中启动程序
Desktop Launcher for Python Script Starts Program in Wrong Path
我无法从在 Linux Mint 17.1 Cinnamon 上创建的 .desktop 启动器启动 python 脚本。
问题是脚本将在错误的路径中启动 - 即 主文件夹 而不是它所在的目录。因此它无法找到其他重要文件随附在其文件夹中,因此不起作用。
为了检查这种不当行为,我创建了一个简短的脚本来检查正在执行 python 脚本的文件夹:
#!/usr/bin/env python
import subprocess
import time
subprocess.call(["pwd"], shell=True)
time.sleep(7) # to get a chance to read the output
从它自己的文件夹中执行它会得到输出:
/home/myusername/PythonProjects
我正在通过 Nemo 的菜单设置桌面启动器。现在执行相同的脚本会产生:
/home/myusername
我不明白这种行为。如何为我的 python 脚本创建一个可用的桌面启动器?
page描述了.desktop
个文件的格式。
您可能会注意到 "Path" 元素,它指定了 运行 中文件的工作目录。在您的情况下,您需要一个指定
的桌面文件
Path=/home/myusername/PythonProjects
如果 Nemo 不允许您设置路径元素,您可能需要手动编辑桌面文件。 .desktop 文件是文本文件,您可以在 /home/myusername/.local/share/applications/
中找到它们
我无法从在 Linux Mint 17.1 Cinnamon 上创建的 .desktop 启动器启动 python 脚本。
问题是脚本将在错误的路径中启动 - 即 主文件夹 而不是它所在的目录。因此它无法找到其他重要文件随附在其文件夹中,因此不起作用。
为了检查这种不当行为,我创建了一个简短的脚本来检查正在执行 python 脚本的文件夹:
#!/usr/bin/env python
import subprocess
import time
subprocess.call(["pwd"], shell=True)
time.sleep(7) # to get a chance to read the output
从它自己的文件夹中执行它会得到输出:
/home/myusername/PythonProjects
我正在通过 Nemo 的菜单设置桌面启动器。现在执行相同的脚本会产生:
/home/myusername
我不明白这种行为。如何为我的 python 脚本创建一个可用的桌面启动器?
page描述了.desktop
个文件的格式。
您可能会注意到 "Path" 元素,它指定了 运行 中文件的工作目录。在您的情况下,您需要一个指定
的桌面文件Path=/home/myusername/PythonProjects
如果 Nemo 不允许您设置路径元素,您可能需要手动编辑桌面文件。 .desktop 文件是文本文件,您可以在 /home/myusername/.local/share/applications/