[Solved] Pyinstallerimporterror: failed to load dynlib/dll (The packaged exe can run normally, but the shortcut generated by exe cannot be started)

#Solution: The created shortcut needs to add the starting position StartIn=str(target).replace(s, "")
import winshell
import os
def create_shortcut_to_desktop():
    target = sys.argv[0]
    title = 'XX shortcut'
    s = os.path.basename(target)
    fname = os.path.splitext(s)[0]
    winshell.CreateShortcut(
        Path=os.path.join(winshell.desktop(), fname + '.lnk'),
        StartIn=str(target).replace(s, ""),
        Target=target,
        Icon=(target, 0),
        Description=title)

def delete_shortcut_from_startup():
    target = sys.argv[0]
    s = os.path.basename(target)
    fname = os.path.splitext(s)[0]
    # delfile = micpath.join(winshell.startup(), fname + '.lnk')
    delfile = os.path.join(winshell.desktop(), fname + '.lnk')
    if os.path.exists(delfile):
        winshell.delete_file(delfile)

Similar Posts: