Installing pyautogui on Ubuntu Server

The Issue

I was recently assisting a QA engineer with some #Fun™ problems on Jenkins where tests running pyautogui (running under Python 2.7) were failing because pyautogui was not installed. Every time we attempted to pip install pyautogui it would give an error similar to the following:

Downloading/unpacking pyautogui
Downloading PyAutoGUI-0.9.36.tar.gz (46kB): 46kB downloaded
Running (path:/tmp/pip-build-tbxln81q/pyautogui/ egg_info for package pyautogui
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip-build-tbxln81q/pyautogui/", line 6, in
File "/tmp/pip-build-tbxln81q/pyautogui/pyautogui/", line 115, in
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-tbxln81q/pyautogui/pyautogui/", line 160, in
_display = Display(os.environ['DISPLAY'])
File "/usr/lib/python3.4/", line 633, in getitem
raise KeyError(key) from None
KeyError: 'DISPLAY'
Complete output from command python egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/tmp/pip-build-tbxln81q/pyautogui/", line 6, in

The Fix

Ensure you have the following packaged installed: xserver-xorg, python-pip, python-xlib, xfce4 (you can use a different desktop env such as Gnome or KDE), and xauth.
sudo apt-get install -y xserver-xorg python-pip python-xlib xfce4 xauth
Also ensure that once you’ve install pip that you upgrade pip by running the following:
pip install --upgrade pip
Open a GUI session either through xrdp (if installed) or console. Once you are here run the following command:
Open an SSH connection to the server and set the $DISPLAY environment variable to match the output of the command above, in my case it was :10.0
export DISPLAY=:10.0
You can confirm this value is set by running the echo command again. Once this is in place run the following to install pyautogui
pip install pyautogui

Other Errors
If you receive any other errors around xauth or xserver try purging and reinstalling the packages above. You may also need to install a few other pip packages such as pillow and xlib.

Creating Bootable USB From ISO on Mac OSX

Insert USB Media and Format

Insert your USB flash drive and use disk utility to format it (press command space to open spotlight search and type Disk Utility). Select the flash drive, choose edit erase and format to MSDOS.

Convert ISO to IMG Format

Once you’ve downloaded your ISO to your machine you will want to open terminal and cd to the directory. Once you’ve done this you’ll want to run the following commands (substituting your path):

hdiutil convert -format UDRW -o /path/to/target.img /path/to/source.iso
Once you’ve done this you’ll want to remove the .dmg extension by running the following (replacing the path with your path)
mv /path/to/target.img.dmg /path/to/target.img

DD the IMG to USB Stick

Next we’ll use the Unix dd command to block copy the img file to the USB. Pay attention to the size of your flash drive when doing these steps as you can cause yourself some headache if you aren’t careful.

diskutil list

Note the path to your drive and proceed to unmount it from the terminal (replacing # with the disk number for your USB stick):
diskutil unmountDisk /dev/disk#

Next we’ll use the dd command specifying the input file (if) which is your img file, and output file (of) which is the path to your USB flash drive, and specify block size (bs). Again where # is a placeholder for the disk number of your USB stick.
sudo dd if=/path/to/downloaded.img of=/dev/rdisk# bs=1m

Finally once this process completes we can eject the flash drive

diskutil eject /dev/disk#
That’s it, you’re ready to go.


Sample of Entire Process With Windows 10 ISO

Richards-MacBook-Pro:~ rstaats$ cd Downloads/
Richards-MacBook-Pro:Downloads rstaats$ hdiutil convert -format UDRW -o en_windows_10_multiple_editions_x64_dvd_6846432.img en_windows_10_multiple_editions_x64_dvd_6846432.iso
Reading J_CCSA_X64FRE_EN-US_DV5 (Apple_UDF : 0)…
Elapsed Time: 10.859s
Speed: 358.6Mbytes/sec
Savings: 0.0%
created: /Users/rstaats/Downloads/en_windows_10_multiple_editions_x64_dvd_6846432.img.dmg
Richards-MacBook-Pro:Downloads rstaats$ mv en_windows_10_multiple_editions_x64_dvd_6846432.img.dmg en_windows_10_multiple_editions_x64_dvd_6846432.img
Richards-MacBook-Pro:Downloads rstaats$ diskutil list
/dev/disk0 (internal):
0: GUID_partition_scheme 251.0 GB disk0
1: EFI EFI 314.6 MB disk0s1
2: Apple_CoreStorage APPLE SSD 250.0 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3

/dev/disk1 (internal, virtual):
0: Apple_HFS APPLE SSD +249.7 GB disk1
Logical Volume on disk0s2
Unlocked Encrypted

/dev/disk2 (external, physical):
0: FDisk_partition_scheme *16.0 GB disk2
1: DOS_FAT_32 U 16.0 GB disk2s1

Richards-MacBook-Pro:Downloads rstaats$ diskutil umountDisk /dev/disk2
Unmount of all volumes on disk2 was successful
Richards-MacBook-Pro:Downloads rstaats$ sudo dd if=en_windows_10_multiple_editions_x64_dvd_6846432.img of=/dev/rdisk2 bs=1m
3894+1 records in
3894+1 records out
4083853312 bytes transferred in 432.072596 secs (9451776 bytes/sec)
Richards-MacBook-Pro:Downloads rstaats$ diskutil eject /dev/disk2
Disk /dev/disk2 ejected
Richards-MacBook-Pro:Downloads rstaats$