[Python] Create a Windows 10 desktop shortcut to run a python script in a venv virtual...

Discussão em 'Python' iniciado por Stack, Novembro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a clickable desktop shortcut for a Windows 10 system that simply executes the following commands that I currently need to repeatedly type in a Windows Powershell:

    PS C:\Users\user> cd C:\Users\username\Documents\PyProject
    PS C:\Users\username\Documents\PyProject> .venv\scripts\activate
    (.venv) C:\Users\username\Documents\PyProject> py -3 .\myscript.py


    I've tried a few of the recommended solutions here, here, and here (including a few others not linked) but all fail by immediately closing the console/command window that is supposed to remain open and print out lines of text from the program.

    Some of my attempts have included:

    • creating a .bat file that I saved in ...\PyProject\ with a shortcut on the desktop.

    @echo off
    cmd /k "cd /d C:\Users\username\Documents\PyProject\.venv\Scripts & .\activate & cd /d C:\Users\username\Documents\PyProject & py -3 myscript.py"

    • using pyinstaller and py2exe

    Any help would be appreciated. Thanks!

    Continue reading...

Compartilhe esta Página