Python脚本的桌面启动器以错误的路径启动程序 [英] Desktop Launcher for Python Script Starts Program in Wrong Path

查看:221
本文介绍了Python脚本的桌面启动器以错误的路径启动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从在Linux Mint 17.1 Cinnamon上创建的.desktop启动器启动python脚本.

I can not launch a python script from a .desktop launcher created on Linux Mint 17.1 Cinnamon.

问题在于该脚本将在错误的路径中启动-即 home文件夹,而不是其放置目录.因此,该脚本无法在其文件夹中找到与其伴随的其他重要文件因此不起作用.

The problem is that the script will be launched in the wrong path - namely the home folder instead of the directory it is placed in. Thereby it can not find other vital files accompanying it in its folder and hence does not work.

要检查该行为,我创建了一个简短的脚本来检查python脚本在其中执行的文件夹:

To examine that misbehaviour I created a short script to check the folder a python script is executing in:

#!/usr/bin/env python

import subprocess
import time

subprocess.call(["pwd"], shell=True)
time.sleep(7)  # to get a chance to read the output

从它自己的文件夹中执行它会得到输出:

Executing it from its own folder gives the output:

/home/myusername/PythonProjects

我正在通过Nemo的菜单设置桌面启动器.现在执行相同的脚本会产生:

I am setting a desktop launcher via Nemo's menu. Now executing the same script yields:

/home/myusername

我不了解此行为.如何为我的python脚本创建可正常工作的桌面启动器?

推荐答案

页面描述了.desktop文件的格式.

您可能会注意到"Path"元素,该元素指定要在其中运行文件的工作目录.在您的情况下,您需要一个指定了

You may note the "Path" element, which specifies the working directory for the file to be run in. In your case you would want a desktop file that specified

Path=/home/myusername/PythonProjects

如果Nemo不允许您设置Path元素,则可能需要手动编辑桌面文件. .desktop文件是文本文件,您可能可以在/home/myusername/.local/share/applications/

If Nemo doesn't allow you to set the Path element you may need to edit the desktop file by hand. The .desktop files are text files and you can probably find them in /home/myusername/.local/share/applications/

这篇关于Python脚本的桌面启动器以错误的路径启动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆