从快捷方式启动时,Python 脚本不运行

问题描述 投票:0回答:1

我在桌面上运行新创建的快捷方式图标时遇到问题。

我使用了脚本:

from pyshortcuts import make_shortcut
import os

# Define paths
source_file = r"my_path_to_source_code"
icon_path = r"/home/user/icons/myicon.icns"
shortcut_name = "Find"
desktop_folder = os.path.join(os.path.expanduser("~"), "Desktop")

shortcut_path = make_shortcut(source_file, name=shortcut_name, icon=icon_path)

desktop_shortcut_path = os.path.join(desktop_folder, f"{shortcut_name}.lnk")

代码运行正常,在桌面上创建了图标,但单击它后,Python 命令提示符会显示一秒钟,然后立即关闭。我还尝试通过 Powershell 创建快捷方式,但出现错误。

python powershell automation command-prompt shortcut
1个回答
0
投票

解决方案:长话短说,使用的 python 快捷方式的路径与 venv 的路径不匹配,并且缺少一些包。在 venv 中创建 python 的快捷方式并添加指向我想要运行的代码的参数解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.