How to Run a Python Script on a PC via a Shortcut
Creating a Desktop Shortcut for a Python Script
Running a Python script through a desktop shortcut on Windows makes launching your projects faster and more convenient. If you’re working with Streamlit, setting up a shortcut can save you from manually activating a virtual environment each time.
1. Standard Python Script Shortcut
Step 1: Locate Your Python Script
Find the script you want to run and note its full file path. Example:
C:\Users\YourName\Scripts\my_script.py
Step 2: Find Your Python Executable
You need the path to Python, which can be found by running:
where python
Example output:
C:\Users\YourName\AppData\Local\Programs\Python\Python39\python.exe
Step 3: Create a Shortcut
- Right-click on the desktop → Select New → Shortcut.
- In the location field, enter:
"C:\path\to\python.exe" "C:\path\to\your_script.py"
Example:
"C:\Users\YourName\AppData\Local\Programs\Python\Python39\python.exe" "C:\Users\YourName\Scripts\my_script.py"
- Click Next, name the shortcut, and click Finish.
Step 4: Modify Shortcut Properties (Optional)
To run the script in the background, replace python.exe
with pythonw.exe
.
2. Running a Streamlit App via a Shortcut
If you’re working with Streamlit, you need to activate your virtual environment before running the app. Here’s how to set up a shortcut that does it automatically.
Step 1: Identify Your Virtual Environment Path
Find your virtual environment’s activate.bat
script. Example:
F:\PYTHON\STREAMLIT\kinopoisk\.venv\Scripts\activate.bat
Step 2: Find Your Streamlit App Path
Locate your app.py
file. Example:
F:\PYTHON\STREAMLIT\kinopoisk\app.py
Step 3: Create a Streamlit Shortcut
- Right-click on the desktop → Select New → Shortcut.
- In the location field, enter:
cmd /k "F:\PYTHON\STREAMLIT\kinopoisk\.venv\Scripts\activate.bat && python -m streamlit run F:\PYTHON\STREAMLIT\kinopoisk\app.py" - Click Next, name the shortcut (e.g., Run Streamlit App), and click Finish.
Step 4: Customize the Shortcut Icon (Optional)
- Right-click the shortcut → Properties.
- Click Change Icon, browse to an
.ico
file, and apply the changes.
3. Running the Script with Administrator Privileges
If your script needs admin rights:
- Right-click the shortcut → Properties.
- Click Advanced → Check Run as administrator.
- Click OK and then Apply.
Now, double-clicking the shortcut will launch your Streamlit app with the correct environment activated! 🚀
Example #1: Streamlit Shortcut
cmd /k "F:\PYTHON\STREAMLIT\kinopoisk\.venv\Scripts\activate.bat && python -m streamlit run F:\PYTHON\STREAMLIT\kinopoisk\app.py"
Example #2: PYTHON Shortcut
cmd /k "cd /d F:\PYTHON\BOTS\RollercoinBot-master && .venv\Scripts\activate.bat && python bot5.py"

Professional data parsing via ZennoPoster, Python, creating browser and keyboard automation scripts. SEO-promotion and website creation: from a business card site to a full-fledged portal.