adb_android:FileNotFoundError: [WinError 2] 系统找不到指定的文件
通过Python调用ADB的时候,你可以选择类似【os.popen】这样的方式,你也可以选择模块包【adb_android】
但是在这个模块包使用的过程中,会遇到如题所示的问题,具体情况如下:
代码:
1 2 3 4 5 |
# code:utf-8 from adb_android import adb_android print(adb_android.devices()) |
报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
G:\Synology_data\SynologyDrive\adamhuan\Python_Interpreter\Discovery_Data\Scripts\python.exe G:/Synology_data/SynologyDrive/adamhuan/Code_Library/Python/Discovery_Data/Test.py *** Executing adb devices command Traceback (most recent call last): File "G:/Synology_data/SynologyDrive/adamhuan/Code_Library/Python/Discovery_Data/Test.py", line 5, in <module> print(adb_android.devices()) File "G:\Synology_data\SynologyDrive\adamhuan\Python_Interpreter\Discovery_Data\lib\site-packages\adb_android\adb_android.py", line 79, in devices return _exec_command(adb_full_cmd) File "G:\Synology_data\SynologyDrive\adamhuan\Python_Interpreter\Discovery_Data\lib\site-packages\adb_android\adb_android.py", line 194, in _exec_command output = check_output(final_adb_cmd, stderr=t) File "D:\Python3\lib\subprocess.py", line 395, in check_output **kwargs).stdout File "D:\Python3\lib\subprocess.py", line 472, in run with Popen(*popenargs, **kwargs) as process: File "D:\Python3\lib\subprocess.py", line 775, in __init__ restore_signals, start_new_session) File "D:\Python3\lib\subprocess.py", line 1178, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。 Process finished with exit code 1 </module> |
解决方法:
修改你的项目中的【subprocess.py】的源码
具体如下:



将上面的【shell=False】,改为【shell=True】;
然后,再次运行就没问题了:
1 2 3 4 5 6 |
G:\Synology_data\SynologyDrive\adamhuan\Python_Interpreter\Discovery_Data\Scripts\python.exe G:/Synology_data/SynologyDrive/adamhuan/Code_Library/Python/Discovery_Data/Test.py *** Executing adb devices command (1, b"'adb' \xb2\xbb\xca\xc7\xc4\xda\xb2\xbf\xbb\xf2\xcd\xe2\xb2\xbf\xc3\xfc\xc1\xee\xa3\xac\xd2\xb2\xb2\xbb\xca\xc7\xbf\xc9\xd4\xcb\xd0\xd0\xb5\xc4\xb3\xcc\xd0\xf2\r\n\xbb\xf2\xc5\xfa\xb4\xa6\xc0\xed\xce\xc4\xbc\xfe\xa1\xa3\r\n") Process finished with exit code 0 |