yizhangliu / android_env_for_windows

Apache License 2.0
5 stars 0 forks source link

TypeError: object of type 'NoneType' has no len() #1

Closed YangBa78 closed 3 years ago

YangBa78 commented 3 years ago

I confronted a problem when running the "run_random_agent_win32.py". The error is:

TypeError: object of type 'NoneType' has no len(),

Any help to sovle the problem? Thanks!

yizhangliu commented 3 years ago

I confronted a problem when running the "run_random_agent_win32.py". The error is:

TypeError: object of type 'NoneType' has no len(),

Any help to sovle the problem? Thanks!

More information about this error? Which file? Which line?

YangBa78 commented 3 years ago

I confronted a problem when running the "run_random_agent_win32.py". The error is: TypeError: object of type 'NoneType' has no len(), Any help to sovle the problem? Thanks!

More information about this error? Which file? Which line?

  1. It happened when I run "run_random_agent_win32.py". Another error I had: TyprError: load() got an unexpected keyword argument 'ask_path'. Traceback (most recent call last): File "c:\android_env\examples\run_random_agent_win32.py", line 89, in app.run(main) File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py", line 303, in run _run_main(main, args) File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py", line 251, in _run_main
    sys.exit(main(argv)) File "c:\android_env\examples\run_random_agent_win32.py", line 52, in main env = android_env.load( TypeError: load() got an unexpected keyword argument 'apk_path'

  2. When running "emulator_console_test.py", I got this: Traceback (most recent call last): File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\mock\mock.py", line 1346, in patched
    return func(*newargs, **newkeywargs) File "c:\android_env\android_env\components\emulator_console_test.py", line 143, in test_send_mouse_action console = emulator_console.EmulatorConsole( File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_console.py", line 176, in init self._setup_fifo() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_console.py", line 259, in _setup_fifo os.mkfifo(self._fifo) AttributeError: module 'os' has no attribute 'mkfifo'

  3. When running "emulator_launcher_test.py". , I got this: Traceback (most recent call last): File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\mock\mock.py", line 1346, in patched
    return func(*newargs, **newkeywargs) File "c:\android_env\android_env\components\emulator_launcher_test.py", line 139, in test_restart launcher.restart() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_launcher.py", line 150, in restart self._kill_emulator_process() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_launcher.py", line 157, in _kill_emulator_process self._emulator.kill(signal.SIGKILL) AttributeError: module 'signal' has no attribute 'SIGKILL'

  4. Is this only suitable for Win32 system? Mine is Windows10 X64. Thanks a lot!

yizhangliu commented 3 years ago

I confronted a problem when running the "run_random_agent_win32.py". The error is: TypeError: object of type 'NoneType' has no len(), Any help to sovle the problem? Thanks!

More information about this error? Which file? Which line?

  1. It happened when I run "run_random_agent_win32.py". Another error I had: TyprError: load() got an unexpected keyword argument 'ask_path'. Traceback (most recent call last): File "c:\android_env\examples\run_random_agent_win32.py", line 89, in app.run(main) File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py", line 303, in run _run_main(main, args) File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "c:\android_env\examples\run_random_agent_win32.py", line 52, in main env = android_env.load( TypeError: load() got an unexpected keyword argument 'apk_path'
  2. When running "emulator_console_test.py", I got this: Traceback (most recent call last): File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\mock\mock.py", line 1346, in patched return func(*newargs, newkeywargs) File "c:\android_env\android_env\components\emulator_console_test.py", line 143, in test_send_mouse_action console = emulator_console.EmulatorConsole( File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_console.py", line 176, in init** self._setup_fifo() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_console.py", line 259, in _setup_fifo os.mkfifo(self._fifo) AttributeError: module 'os' has no attribute 'mkfifo'
  3. When running "emulator_launcher_test.py". , I got this: Traceback (most recent call last): File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\mock\mock.py", line 1346, in patched return func(*newargs, **newkeywargs) File "c:\android_env\android_env\components\emulator_launcher_test.py", line 139, in test_restart launcher.restart() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_launcher.py", line 150, in restart self._kill_emulator_process() File "C:\Users\alex7\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env\components\emulator_launcher.py", line 157, in _kill_emulator_process self._emulator.kill(signal.SIGKILL) AttributeError: module 'signal' has no attribute 'SIGKILL'
  4. Is this only suitable for Win32 system? Mine is Windows10 X64. Thanks a lot!

Sorry. I made a mistake. I've fixed it. Pull again. You can test it: 1.pull code to c:/android_env_for_windows 2.cd c:/android_env_for_windows 3.pip install -e . 4.python examples\run_random_agent_win32.py

YangBa78 commented 3 years ago

Thanks for your work. I tried it again. It went well in step 1-3. But still got errors in step 4:

FileNotFoundError Traceback (most recent call last) c:\android_env_for_windows\examples\run_random_agent_win32.py in 87 logging.set_stderrthreshold('info') 88 # flags.mark_flags_as_required(['avd_name', 'task_path']) ---> 89 app.run(main)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py in run(main, argv, flags_parser) 301 callback() 302 try: --> 303 _run_main(main, args) 304 except UsageError as error: 305 usage(shorthelp=True, detailed_error=error, exitcode=error.exitcode)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py in _run_main(main, argv) 249 sys.exit(retval) 250 else: --> 251 sys.exit(main(argv)) 252 253

c:\android_env_for_windows\examples\run_random_agentwin32.py in main() 50 def main(_): 51 ---> 52 env = android_env.load( 53 emulator_path=FLAGS.emulator_path, 54 android_sdk_root=FLAGS.android_sdk_root,

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\loader.py in load(task_path, avd_name, android_avd_home, android_sdk_root, emulator_path, adb_path, apk_path, run_headless) 51 52 # Create simulator. ---> 53 simulator = emulator_simulator.EmulatorSimulator( 54 emulator_launcher_args=dict( 55 avd_name=avd_name,

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\emulator_simulator.py in init(self, emulator_launcher_args, emulator_console_args, kwargs) 61 'grpc_port', portpicker.pick_unused_port()) 62 ---> 63 super().init(kwargs) 64 65 self._emulator_stub = None

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\base_simulator.py in init(self, adb_path, adb_server_port, prompt_regex, apk_path, tmp_dir, kvm_device, show_touches, show_pointer_location, show_status_bar, show_navigation_bar) 72 self._show_navigation_bar = show_navigation_bar 73 ---> 74 self._local_tmp_dir_handle = tempfile.TemporaryDirectory(dir=tmp_dir) 75 self._local_tmp_dir = self._local_tmp_dir_handle.name 76 logging.info('Simulator local_tmp_dir: %s', self._local_tmp_dir)

~\AppData\Local\Programs\Python\Python39\lib\tempfile.py in init(self, suffix, prefix, dir) 777 778 def init(self, suffix=None, prefix=None, dir=None): --> 779 self.name = mkdtemp(suffix, prefix, dir) 780 self._finalizer = _weakref.finalize( 781 self, self._cleanup, self.name,

~\AppData\Local\Programs\Python\Python39\lib\tempfile.py in mkdtemp(suffix, prefix, dir) 357 _sys.audit("tempfile.mkdtemp", file) 358 try: --> 359 _os.mkdir(file, 0o700) 360 except FileExistsError: 361 continue # try again

FileNotFoundError: [WinError 3] The system cannot find the path specified: '/tmp\tmp85p52fps'

yizhangliu commented 3 years ago

Try to create a directory: c:/tmp

YangBa78 commented 3 years ago

I can successfully initialize the emulator, but the code stops running once the phone is done initialization.

I0621 02:15:33.804947 12856 emulator_launcher.py:135] Waiting for boot for 300.0 seconds... I0621 02:17:13.462516 12856 emulator_launcher.py:145] Done booting the emulator (in 99.664277 seconds). ___self.fifo/tmp\tmp0jb40hgv\screenshot_pipe-93b05454-7464-4cf8-af88-6d381d4d7be5.pb___

AttributeError Traceback (most recent call last) c:\android_env_for_windows\examples\run_random_agent_win32.py in 87 logging.set_stderrthreshold('info') 88 # flags.mark_flags_as_required(['avd_name', 'task_path']) ---> 89 app.run(main)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py in run(main, argv, flags_parser) 301 callback() 302 try: --> 303 _run_main(main, args) 304 except UsageError as error: 305 usage(shorthelp=True, detailed_error=error, exitcode=error.exitcode)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\absl\app.py in _run_main(main, argv) 249 sys.exit(retval) 250 else: --> 251 sys.exit(main(argv)) 252 253

c:\android_env_for_windows\examples\run_random_agentwin32.py in main() 50 def main(_): 51 ---> 52 env = android_env.load( 53 emulator_path=FLAGS.emulator_path, 54 android_sdk_root=FLAGS.android_sdk_root,

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\loader.py in load(task_path, avd_name, android_avd_home, android_sdk_root, emulator_path, adb_path, apk_path, run_headless) 74 75 task_manager = task_manager_lib.TaskManager(task) ---> 76 coordinator = coordinator_lib.Coordinator(simulator, task_manager) 77 78 # Load environment.

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\coordinator.py in init(self, simulator, task_manager, step_timeout_sec, max_steps_per_sec, periodic_restart_time_min, force_simulator_launch) 86 self._simulator_start_time = None 87 ---> 88 self._restart_simulator() 89 90 def action_spec(self) -> Dict[str, dm_env.specs.Array]:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\coordinator.py in _restart_simulator(self, max_retries) 179 if self._force_simulator_launch or not self._simulator.is_launched(): 180 self._task_manager.pause_task() --> 181 self._simulator.launch() 182 self._simulator_start_time = time.time() 183 adb_controller = self._simulator.create_adb_controller()

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\base_simulator.py in launch(self) 136 if not self._launched: 137 self._launched = True --> 138 self._launch_impl() 139 self._post_launch_setup() 140 else:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\emulator_simulator.py in _launch_impl(self) 109 self._launcher.launch() 110 if self._grpc_port < 0: --> 111 self._start_console() 112 except errors.SimulatorCrashError: 113 # If the simulator crashes on the initial launch, we try to restart once.

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\emulator_simulator.py in _start_console(self) 93 94 def _start_console(self) -> None: ---> 95 self._console = emulator_console.EmulatorConsole( 96 **self._emulator_console_args) 97

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\emulator_console.py in init(self, console_port, auth_code, tmp_dir, pipe_read_timeout_sec) 174 self._pipe_read_timeout_sec = pipe_read_timeout_sec 175 self._read_thread = None --> 176 self._setup_fifo() 177 self._connect() 178 self._authenticate_to_console(auth_code)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\android_env_for_windows-1.0.0-py3.9.egg\android_env\components\emulator_console.py in _setup_fifo(self) 258 # fast and loud. 259 if sys.platform != 'win64': --> 260 os.mkfifo(self._fifo) 261 else: 262 file = open(self._fifo, 'w')

AttributeError: module 'os' has no attribute 'mkfifo'

yizhangliu commented 3 years ago

Why 'win64'? Keep this: 259 if sys.platform != 'win32':

YangBa78 commented 3 years ago

My laptop is win64, but I didn't change the code. Does it work on win64?

yizhangliu commented 3 years ago

259 if sys.platform != 'win64': --> 260 os.mkfifo(self._fifo)

-- According to your information, your system is not 'win64'. You should check it in python console: print(sys.platform)

YangBa78 commented 3 years ago

The output is win32. Strange....

What should I do next?

yizhangliu commented 3 years ago

Not strange. Your python is 32 bit.
Next, you should modified 'win64' to 'win32'. Good luck.

yizhangliu commented 3 years ago

To avoid puzzle, I've modified some code. Like this: platform.system() != 'Windows' Replace for:
sys.platform != 'win32':

YangBa78 commented 3 years ago

It works. Thanks for your help. I really appreciate it! The code works well for the windows. You could close this issue.