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

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

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

1 C:\Windows\system32>python3 -m weditor
2 Traceback (most recent call last):
3   File "C:\Program Files\Python37\lib\runpy.py", line 193, in _run_module_as_main
4     "__main__", mod_spec)
5   File "C:\Program Files\Python37\lib\runpy.py", line 85, in _run_code
6     exec(code, run_globals)
7   File "C:\Program Files\Python37\lib\site-packages\weditor\__main__.py", line 19, in <module>
8     import StringIO
9 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 -m weditor 时,还是报错,不过是报另外一个错,说明上面的问题已经解决,下面来看看第二个错是什么样的,提示没有 cv2模块

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

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

 

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

 

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

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

 

posted @ 2018-09-10 10:44  iSZ  阅读(1864)  评论(0编辑  收藏  举报