实际情形有可能是:
tests/test_enlighten.py:1: in <module> import re, sys, signal, logging, argparse, pyautogui, subprocess /usr/lib/python2.7/site-packages/pyautogui/__init__.py:115: in <module> from . import _pyautogui_x11 as platformModule /usr/lib/python2.7/site-packages/pyautogui/_pyautogui_x11.py:160: in <module> _display = Display(os.environ['DISPLAY']) /usr/lib64/python2.7/UserDict.py:23: in __getitem__ raise KeyError(key) E KeyError: 'DISPLAY'
极有可能是由于shell环境中对于图形输出的设置获取或识别失败,此类情况还有可能出现在用shell打开浏览器。一般都是`DISPLAY`云云。
在shell中的做法:
#!/bin/bash export DISPLAY=:0
在Python脚本中的做法:
#! python3 #导入os模块设置DISPLAY import os os.environ['DISPLAY'] = ':0' #再导入pyautogui import pyautogui #其他操作