I'm creating an installer for a program that I'll be distributing to my colleagues. I would like to set the default location for the program's shortcut to be a custom location that uses a Windows system folder reference as the first part of the path. However, whenever I run the installer after compiling, I get an error:
The installer has encountered an unexpected error installing this package.
This may indicate a problem with this package. The error code is 2756.
I've isolated the error to the shortcut directory argument in my setup.py file.
from cx_Freeze import setup, Executable
executables = [Executable(
script='__main__.py',
base='Console',
target_name='my-program',
shortcutName='my-program-shortcut',
shortcutDir=<arg that throws error>, ### This one is the problem
)]
options = {
'bdist_msi': {
'initial_target_dir': fr'[PersonalFolder]My Program Apps\my-program'
}
}
setup(
name='my-program',
executables=executables,
options=options,
)
For the shortcutDir parameter above, I would like the destination to be C:\Users\myUserName\Documents\My Department Apps.
The System Folder Properties reference tells me that PersonalFolder is the keyword I need to use to access the Documents\ directory--and indeed, when I pass in 'PersonalFolder' as the argument for shortcutDir, everything works fine.
# This works fine
executables = [Executable(
script='__main__.py',
base='Console',
target_name='my-program',
shortcutName='my-program-shortcut',
shortcutDir='PersonalFolder',
)]
It's when I try to go one click down to the My Program Apps\ directory within the PersonalFolder that I run into trouble. Here are the arguments that haven't worked:
r'[PersonalFolder]My Department Apps'r'[PersonalFolder]\My Department Apps'r'PersonalFolder\My Department Apps'
It's strange, because passing r'[PersonalFolder]My Department Apps\my-program' to initial_target_dir as a bdist_msi option works as expected--it looks for the My Department Apps\ directory within PersonalFolder (i.e., C:\Users\myUserName\Documents) and, if it doesn't find it, creates it; it looks for the my-program\ directory in there and, if it doesn't find it, creates it; and then it puts all the compiled code into that directory.
I've already tried creating the shortcut with a shortcut table (also detailed here) and I ran into the same error.
I haven't been able to find any resources that give an overview of how to use Windows Property References (e.g., PersonalFolder) in setup.py files. I seem to be breaking some rule that I'm unaware of--e.g., perhaps you can use them in longer paths for some arguments that you pass to setup() but not others?
If anyone can offer guidance on how to do this, I'd be grateful!