yas*_*sar 7 python windows installer setuptools startmenu
我想为我的Python Windows安装程序包创建一个开始菜单或桌面快捷方式.我试图关注https://docs.python.org/3.4/distutils/builtdist.html#the-postinstallation-script
这是我的剧本;
import sys
from os.path import dirname, join, expanduser
pyw_executable = sys.executable.replace('python.exe','pythonw.exe')
script_file = join(dirname(pyw_executable), 'Scripts', 'tklsystem-script.py')
w_dir = expanduser(join('~','lsf_files'))
print(sys.argv)
if sys.argv[1] == '-install':
print('Creating Shortcut')
create_shortcut(
target=pyw_executable,
description='A program to work with L-System Equations',
filename='L-System Tool',
arguments=script_file,
workdir=wdir
)
Run Code Online (Sandbox Code Playgroud)
我还在脚本设置选项中指定了此脚本,如上述文档所示.
这是我用来创建安装程序的命令;
python setup.py bdist_wininst --install-script tklsystem-post-install.py
Run Code Online (Sandbox Code Playgroud)
在使用创建的Windows安装程序安装我的软件包之后,我无法找到创建shorcut的位置,也无法确认我的脚本是否运行?
如何使setuptools生成Windows安装程序以创建桌面或开始菜单快捷方式?
如果要确认脚本是否正在运行,可以打印到文件而不是控制台。看起来您在安装后脚本中打印到控制台的文本不会显示。
尝试这个:
import sys
from os.path import expanduser, join
pyw_executable = join(sys.prefix, "pythonw.exe")
shortcut_filename = "L-System Toolsss.lnk"
working_dir = expanduser(join('~','lsf_files'))
script_path = join(sys.prefix, "Scripts", "tklsystem-script.py")
if sys.argv[1] == '-install':
# Log output to a file (for test)
f = open(r"C:\test.txt",'w')
print('Creating Shortcut', file=f)
# Get paths to the desktop and start menu
desktop_path = get_special_folder_path("CSIDL_COMMON_DESKTOPDIRECTORY")
startmenu_path = get_special_folder_path("CSIDL_COMMON_STARTMENU")
# Create shortcuts.
for path in [desktop_path, startmenu_path]:
create_shortcut(pyw_executable,
"A program to work with L-System Equations",
join(path, shortcut_filename),
script_path,
working_dir)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2789 次 |
| 最近记录: |