Python Forum
Creating Shortcuts with python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Creating Shortcuts with python (/thread-37524.html)



Creating Shortcuts with python - Oshadha - Jun-22-2022

Is there a way for me to create a shortcut (.lnk) file using python. I searched everywhere, but found no answer that works :(


RE: Creating Shortcuts with python - snippsat - Jun-22-2022

Both pywin32 and winshell shortcut can do this.
Can do quick test with to see in work with newest Python 3.10.5 as winshell is old.
import os, sys
import winshell

link_filepath = os.path.join(winshell.desktop(), "python.lnk")
with winshell.shortcut(link_filepath) as link:
  link.path = sys.executable
  link.description = "Shortcut to python" 
Work fine create a working shortcut to Python on the Desktop.


RE: Creating Shortcuts with python - Oshadha - Jun-23-2022

(Jun-22-2022, 12:13 PM)snippsat Wrote: Both pywin32 and winshell shortcut can do this.
Can do quick test with to see in work with newest Python 3.10.5 as winshell is old.
import os, sys
import winshell

link_filepath = os.path.join(winshell.desktop(), "python.lnk")
with winshell.shortcut(link_filepath) as link:
  link.path = sys.executable
  link.description = "Shortcut to python" 
Work fine create a working shortcut to Python on the Desktop.

Throws this error:
Error:
Traceback (most recent call last): File "d:\1. Oshadha\2. Code\Python\Test.py", line 2, in <module> import winshell File "C:\Users\DELL\AppData\Local\Programs\Python\Python310\lib\site-packages\winshell.py", line 30, in <module> import win32con ModuleNotFoundError: No module named 'win32con'
When I try pip install win32con

It gives another error:
Error:
ERROR: Could not find a version that satisfies the requirement win32con (from versions: none) ERROR: No matching distribution found for win32con
Im using the newest version of python: 3.10.5 64Bit

I found many websites using this winshell module and I gave up because it gave the same error.


EDIT: I solved the error.
pip install pywin32 solves the issue!
Thanks for everyone's help!