Ojakokko
Ojakokko

Reputation: 41

Python script runs correctly via cmd but not on double-clicking

I have built a simple auto-clicker with python. The script runs properly when executing via cmd with the "python.exe F:\Directories\moreDirectories\myScript.py" command, but not on double-clicking the icon.

import pyautogui
pyautogui.click(600,250)
exit = input("press enter to close the program")

I'm assuming the problem is with importing pyautogui, as it runs if I remove all the pyautogui parts (making it the most useless program ever, only prompting the user to close it). I made a batch file to run it via cmd more easily, but as it happens it opens the command prompt right on the spot it is supposed to click (not that it would've been a very elegant solution anyways). I have pyautogui installed via pip in Lib\site-packages

Upvotes: 0

Views: 2382

Answers (2)

QcO
QcO

Reputation: 41

I know this thread is old, but just thought I'd mention this for future visitors:

If you installed python through the Microsoft store, uninstall it and redownload it from the python website. This will fix this issue.

Upvotes: 4

Filip Dimitrovski
Filip Dimitrovski

Reputation: 1726

Your Windows is configured to run .py files with Visual Studio's Python. Right click the file, select open with... and find the python.exe that you want to use.

The other possibility is that your environment variables (which can be changed using Windows tools) for your Windows user or the whole system contain PYTHONNOUSERSITE, PYTHONUSERBASE or PYTHONPATH and they are incorrectly set to the Visual Studio Python version.

Upvotes: 1

Related Questions