python3中启动 uiautomator2viewer时报错解决办法

事先说明:我电脑里同时了安装了 python2和python3,启动对应版本时分别带上版本号,如何设置共存请参考:python2与python3共存

打开命令窗口,启动weditor : python3 -m weditor,报如下错误:

 C:\Windows\system32>python3 -m weditor
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python37\lib\site-packages\weditor\__main__.py", line 19, in <module>
import StringIO
ModuleNotFoundError: No module named 'StringIO'

查阅了一下别人博客说明,在Python3中没有直接通过 import StringIO的方法(在python2中使用),正确的使用方法为 from io import StringIO,根据上面错误输出中的解决办法,到 C:\Program Files\Python37\Lib\site-packages\weditor 将 “__main__.py” 文件中第19行修改为 from io import StringIO (我是重新新增一行,把原语句注释掉)

python3中启动 uiautomator2viewer时报错解决办法

再次运行 Python3 -m weditor 时,还是报错,不过是报另外一个错,说明上面的问题已经解决,下面来看看第二个错是什么样的,提示没有 cv2模块

 C:\Windows\system32>python3 -m weditor
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Program Files\Python37\lib\site-packages\weditor\__main__.py", line 24, in <module>
import atx
File "C:\Program Files\Python37\lib\site-packages\atx\__init__.py", line 22, in <module>
from atx.drivers import Pattern, Bounds, ImageCrop
File "C:\Program Files\Python37\lib\site-packages\atx\drivers\__init__.py", line 9, in <module>
from atx import imutils
File "C:\Program Files\Python37\lib\site-packages\atx\imutils.py", line 16, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'

那就再安装 cv2模块,不过这个模块的安装方法跟其它模块有点不一样,不能直接通过名字的形式去猜测安装方法,一般人都是直接 pip3 install cv2,结果会发现这个行不通,通过查阅其它人博客,该cv2 模块的正确安装方法是 pip3 install opencv-python

 C:\Windows\system32>pip3 install opencv-python
Collecting opencv-python
Downloading https://files.pythonhosted.org/packages/82/de/32bdf7b20f9d08008dda2073a48141ab4ad829deaca7aa660e9c64d02dae/opencv_python-3.4.3.18-cp37-cp37m-win_amd64.whl (33.8MB)
100% |████████████████████████████████| 33.8MB 280kB/s
Requirement already satisfied: numpy>=1.14.5 in c:\program files\python37\lib\site-packages (from opencv-python) (1.15.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.4.3.18

再次启动 python3 -m weditor,网页版的 uiautomatorviewer 正常打开

 C:\Windows\system32>python3 -m weditor
listen port 17310
[I 180910 10:29:11 web:2162] 304 GET /api/v1/version (::1) 0.00ms
[I 180910 10:29:15 web:2162] 200 POST /api/v1/connect (::1) 828.14ms
SN 55115076-099d-4f9c-b11a-8ada31375c5e
[I 180910 10:29:29 web:2162] 200 GET /api/v1/devices/55115076-099d-4f9c-b11a-8ada31375c5e/screenshot (::1) 1092.94ms
[I 180910 10:29:30 web:2162] 200 GET /api/v1/devices/55115076-099d-4f9c-b11a-8ada31375c5e/hierarchy (::1) 724.49ms

python3中启动 uiautomator2viewer时报错解决办法

上一篇:java中<> 的用法


下一篇:转 Kafka、RabbitMQ、RocketMQ等消息中间件的对比 —— 消息发送性能和优势