0

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

2
  • Make a new py file with import site and input(site.getsitepackages()). Double click it and compare the folders with the folder where pyautogui is installed. Commented Apr 12, 2019 at 20:48
  • Apparently it was importing from the Visual Studio python directory, moved pyautogui there and now it works. Any idea why it was importing from there even though I wasn't using VS for the program? Commented Apr 12, 2019 at 21:00

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.