0

I am attempting to use a small script to move my mouse slightly every minute or two to make the appearance that I am sitting at my desk (dont tell my boss please)

is anyone able to assist in why this might be happening?

from my command prompt I was able to successfully install pip install pyautogui

note, that: pip3 install autogui was not recognized

once I opened up pycharm, I ran the code, and got the below error:

ModuleNotFoundError: No module named 'pyautogui'

  • I also checked to make sure I had python 3 in command line using pip version = anaconda3\lib\site-packages\pip (python 3.7)

**full code below for reference

import pyautogui
import time
import sys
from datetime import datetime
pyautogui.FAILSAFE = False
numMin = None
if ((len(sys.argv)<2) or sys.argv[1].isalpha() or int(sys.argv[1])<1):
    numMin = 1
else:
    numMin = int(sys.argv[1])
while(True):
    x=0
    while(x<numMin):
        time.sleep(60)
        x+=1
    for i in range(0,200):
        pyautogui.moveTo(0,i*4)
    pyautogui.moveTo(1,1)
    for i in range(0,3):
        pyautogui.press("shift")
    print("Movement made at {}".format(datetime.now().time()))

https://github.com/Johnson468/Stay-Awake

for reference - i am using windows

pepperjack
  • 67
  • 7

2 Answers2

1

You cannot import pyautogui from python 3 interpreter in pycharm because it is not installed.
When you ran pip install pyautogui you installed it on your python2.7 environment.

When you tried to installed it with pip3 you ran anaconda's pip (accordint to you error).
you can check which pip is used inside the CMD with the command where pip3.

If it is not found you can try running it like this: python -m pip but make sure you are running python3!

I highly recommend installing everything in venv virtual environment to make sure nothing is missing and you don't have any dependencies issues.
Or if you are new to python, uninstall all different instances and only keep one (probably python3 in your case), or edit you PATH in Windows

Furthermore I'm pretty sure when you are running pip from your console you are using another instance of it on your computer then the one you set as interpreter on pycharm, hence you couldn't use pip3 at all.

If none of the above helped, please add more details yo your question and I'll edit the answer.

Summary: You have a few instances of python installed on your computer (at least one of python2.7 and one of anaconda), when you run python or pip from the CMD if refers to the python2.7 one.
But when you chose an interpreter for you project in Pycharm you chose a python3 instance, which is obviously doesn't contain pyautogui.
Make sure you are using the right python instance when setting it up in Pycharm and when installing packages.

Mogi
  • 596
  • 1
  • 6
  • 18
  • HI, I have a windows computer. I thought by using the pip version check on my command line that confirmed it was installed direct to 3.7 ? as for the VENV suggestion, do I need to add anything to your 'sudo' installation in order for it to work on windows? – pepperjack Aug 14 '20 at 14:28
0

I answered this question recently: Problem with Python modules import on Mac

The issue might be that you don't have pip installed.

I know most Mac's have pip and Python pre-installed, but it wouldn't hurt to try: sudo easy_install pip

If this doesn't seem to be the issue, you might be running the pip install packageName in the wrong directory.

You will need to access your scripts folder in python and run the pip install packageName command in there. Here is a resource which should help you reach that directory: https://datatofish.com/install-package-python-using-pip/

This was answered for a Mac, but switching the commands to another OS shouldn't be hard. Just make sure pip is installed and that you're installing in the right directory.

lime
  • 801
  • 8
  • 21