Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't import pyautogui
#1
import time
import random
import pyautogui # This causes import error!
from selenium import webdriver
This has got to be some rookie error, but when I try to import pyautogui, I get the following:
import pyautogui
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pyautogui'

I get the same problem with pywinauto.

I am running Windoze 10
sys.version_info
sys.version_info(major=3, minor=7, micro=1, releaselevel='final', serial=0)
IDE is pycharm

pyautogui is already installed, according to this:
C:\>pip3 install pyautogui
Requirement already satisfied: pyautogui in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (0.9.39)
Requirement already satisfied: pymsgbox in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (1.0.6)
Requirement already satisfied: PyTweening>=1.0.1 in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (1.0.3)
Requirement already satisfied: Pillow in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (5.4.0)
Requirement already satisfied: pyscreeze in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (0.1.18)

Python in in my path. I don't have any problem with importing time, sys, or other modules.

Please tell me what I am doing wrong...
Reply
#2
you need to install the package, from command line:
pip install pyautogui
Reply
#3
Per the original post, I already did that.

I tried both pip and pip3, I'm assuming they both do the same thing. This is from the command line:
C:\>pip install pyautogui
Requirement already satisfied: pyautogui in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (0.9.39)
Requirement already satisfied: pymsgbox in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (1.0.6)
Requirement already satisfied: PyTweening>=1.0.1 in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (1.0.3)
Requirement already satisfied: Pillow in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (5.4.0)
Requirement already satisfied: pyscreeze in c:\users\howard\appdata\local\programs\python\python37-32\lib\site-packages (from pyautogui) (0.1.18)
Reply
#4
(Jan-02-2019, 02:12 AM)HowardHarkness Wrote: IDE is pycharm

You might have multiple Python installations.

The one in your path seems to be
Quote:c:\users\howard\appdata\local\programs\python\python37-32

Also, make sure you are using the same interpreter in PyCharm:
Quote:settings (ctrl+alt+s) -> Project -> Project Interpreter
Reply
#5
As mention bye @hbknjr check interpreter in PyCharm

Here some basic test from command line.
C:\
λ python -c "import sys; print(sys.executable)"
C:\python37\python.exe

C:\
λ pip -V
pip 18.1 from c:\python37\lib\site-packages\pip (python 3.7)

C:\
λ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyautogui
>>>
>>> pyautogui.__version__
'0.9.39'
>>> exit()
Now can test in PyCharm with:
import sys
import pyautogui

print(sys.executable)
print('hello world')
print(pyautogui.__version__)
Output:
C:\Python37\python.exe hello world 0.9.39
As you see same Python interpreter(C:\Python37\python.exe) in command line and in script is used,then it will work.
Reply
#6
Thank you!

There were indeed two different pythons installed -- even though both were the same version. Took me a while to figure out how to change the setting in PyCharm, but once I did, the import statements worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pyautogui samin 0 474 Nov-03-2020, 03:47 PM
Last Post: samin

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020