Skip to content

Cannot import pyautogui due to pygetwindow not supporting linux #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jfmoulin opened this issue Jan 6, 2019 · 2 comments
Open

Cannot import pyautogui due to pygetwindow not supporting linux #291

jfmoulin opened this issue Jan 6, 2019 · 2 comments

Comments

@jfmoulin
Copy link

jfmoulin commented Jan 6, 2019

Just installed pyautogui 0.9.40 via pip3 under Linux Mint 19.1.
I cannot import the module due to pygetwindow not being supported on Linux.
Code seen in init.py suggests that some methods should be missing but the NotImplementedError of pygetwindow is not properly caught.

Trace of an Ipython session where I got the problem:

In [3]: import pyautogui

NotImplementedError                       Traceback (most recent call last)
<ipython-input-3-fa2587ca3a04> in <module>()
----> 1 import pyautogui

/usr/local/lib/python3.6/dist-packages/pyautogui/__init__.py in <module>()
93 
94 try:
---> 95     import pygetwindow
96     from pygetwindow import Window, getFocusedWindow, getWindowsAt, getWindowsWithTitle, getAllWindows, getAllTitles
97 except ImportError:

/usr/local/lib/python3.6/dist-packages/pygetwindow/__init__.py in <module>()
40     Window = Win32Window
41 else:
---> 42     raise NotImplementedError('PyGetWindow currently does not support Linux. If you have Xlib knowledge, please contribute! https://github.com/asweigart/pygetwindow')
 43 
 44 

NotImplementedError: PyGetWindow currently does not support Linux. If you have Xlib knowledge, please contribute! https://github.com/asweigart/pygetwindow
`

@saildata
Copy link

saildata commented Jan 8, 2019

@jfmoulin it looks like the recent work on pygetwindow has pushed directly into the main line of pyautogui, which breaks for Linux users at the moment.

The solution I found is to use the PyPi snapshot/release 0.9.39. I tested it out and copied my work below for anyone else who comes across this before it's fixed.

[:~/projects] $ mkd pyautogui_linux_09_39

[:~/projects/pyautogui_linux_09_39] $ pipenv shell
Creating a Pipfile for this project…
Launching subshell in virtual environment…
. .local/share/virtualenvs/pyautogui_linux_09_39-6lzKIWuD/bin/activate

[:~/projects/pyautogui_linux_09_39] $ . .local/share/virtualenvs/pyautogui_linux_09_39-6lzKIWuD/bin/activate

[:~/projects/pyautogui_linux_09_39] [pyautogui_linux_09_39-6lzKIWuD] $ pipenv install pyautogui==0.9.39
Installing pyautogui==0.9.39…
Adding pyautogui to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (912a61)!
Installing dependencies from Pipfile.lock (912a61)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 5/5 — 00:00:00

[:~/projects/pyautogui_linux_09_39] [pyautogui_linux_09_39-6lzKIWuD] $ pipenv install xlib
Installing xlib…
Adding xlib to Pipfile's [packages]…
✔ Installation Succeeded
Pipfile.lock (3bb3fe) out of date, updating to (912a61)…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
✔ Success!
Updated Pipfile.lock (3bb3fe)!
Installing dependencies from Pipfile.lock (3bb3fe)…
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 7/7 — 00:00:00

[:~/projects/pyautogui_linux_09_39] [pyautogui_linux_09_39-6lzKIWuD] $ cat ./pyautogui_linux_09_39_example.py

#!/usr/bin/env python3

import pyautogui

# watch -n1 "python pyautogui_linux_09_39.py"
# to get the coordinates of the target window
#currentMouseX, currentMouseY = pyautogui.position()
#print(currentMouseX, currentMouseY)

pyautogui.moveTo(746, 588) # go to VIM window
pyautogui.click()

pyautogui.press('i')  #activate INSERT mode in VIM
pyautogui.PAUSE = 0.50
pyautogui.typewrite('Hello world!', interval=0.25)  # type with quarter-second pause in between each key

pyautogui.press('esc')
pyautogui.press(['d', 'd'])  # delete the current line

# and replace it with a penguin emoji; Unicode U+1F427 🐧
pyautogui.press('i')
pyautogui.hotkey('ctrl', 'shift', 'u')
pyautogui.press(['1', 'f', '4', '2', '7'])
pyautogui.press('enter')
pyautogui.press('esc')

[:~/projects/pyautogui_linux_09_39] [pyautogui_linux_09_39-6lzKIWuD] $ python ./pyautogui_linux_09_39_example.py

@dkatz23238
Copy link

This works for me as well. Chaning to version 0.9.39.

What are ongoing plans for this fix? Will the main branch support linux without any additional work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants