0

I'm studying machinelearning courses of Andrew NG and doing the lab that give.But I meet error in running code in jupyter lab.Down below is my code:

import time
from collections import deque, namedtuple

import gym
import numpy as np
import PIL.Image
import tensorflow as tf
import utils

from pyvirtualdisplay import Display
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.losses import MSE
from tensorflow.keras.optimizers import Adam
# Set up a virtual display to render the Lunar Lander environment.
Display(visible=0, size=(840, 480)).start();
# Set the random seed for TensorFlow
tf.random.set_seed(utils.SEED)

this code doesn't work and shows error message in the following paragraph.

 FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 2
      1 # Set up a virtual display to render the Lunar Lander environment.
----> 2 Display(visible=0, size=(840, 480)).start();
      4 # Set the random seed for TensorFlow
      5 tf.random.set_seed(utils.SEED)

File ~\mambaforge\envs\tf2\Lib\site-packages\pyvirtualdisplay\display.py:54, in Display.__init__(self, backend, visible, size, color_depth, bgcolor, use_xauth, retries, extra_args, manage_global_env, **kwargs)
     51 if not cls:
     52     raise ValueError("unknown backend: %s" % self._backend)
---> 54 self._obj = cls(
     55     size=size,
     56     color_depth=color_depth,
     57     bgcolor=bgcolor,
     58     retries=retries,
     59     use_xauth=use_xauth,
     60     # check_startup=check_startup,
     61     extra_args=extra_args,
     62     manage_global_env=manage_global_env,
     63     **kwargs
     64 )

File ~\mambaforge\envs\tf2\Lib\site-packages\pyvirtualdisplay\xvfb.py:44, in XvfbDisplay.__init__(self, size, color_depth, bgcolor, use_xauth, fbdir, dpi, retries, extra_args, manage_global_env)
     41 self._fbdir = fbdir
     42 self._dpi = dpi
---> 44 AbstractDisplay.__init__(
     45     self,
     46     PROGRAM,
     47     use_xauth=use_xauth,
     48     retries=retries,
     49     extra_args=extra_args,
     50     manage_global_env=manage_global_env,
     51 )

File ~\mambaforge\envs\tf2\Lib\site-packages\pyvirtualdisplay\abstractdisplay.py:85, in AbstractDisplay.__init__(self, program, use_xauth, retries, extra_args, manage_global_env)
     82 self._pipe_wfd = None
     83 self._retries_current = 0
---> 85 helptext = get_helptext(program)
     86 self._has_displayfd = "-displayfd" in helptext
     87 if not self._has_displayfd:

File ~\mambaforge\envs\tf2\Lib\site-packages\pyvirtualdisplay\util.py:13, in get_helptext(program)
      6 cmd = [program, "-help"]
      8 # py3.7+
      9 # p = subprocess.run(cmd, capture_output=True)
     10 # stderr = p.stderr
     11 
     12 # py3.6 also
---> 13 p = subprocess.Popen(
     14     cmd,
     15     stdout=subprocess.PIPE,
     16     stderr=subprocess.PIPE,
     17     shell=False,
     18 )
     19 _, stderr = p.communicate()
     21 helptext = stderr.decode("utf-8", "ignore")

File ~\mambaforge\envs\tf2\Lib\subprocess.py:1026, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize, process_group)
   1022         if self.text_mode:
   1023             self.stderr = io.TextIOWrapper(self.stderr,
   1024                     encoding=encoding, errors=errors)
-> 1026     self._execute_child(args, executable, preexec_fn, close_fds,
   1027                         pass_fds, cwd, env,
   1028                         startupinfo, creationflags, shell,
   1029                         p2cread, p2cwrite,
   1030                         c2pread, c2pwrite,
   1031                         errread, errwrite,
   1032                         restore_signals,
   1033                         gid, gids, uid, umask,
   1034                         start_new_session, process_group)
   1035 except:
   1036     # Cleanup if the child failed starting.
   1037     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~\mambaforge\envs\tf2\Lib\subprocess.py:1538, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_gid, unused_gids, unused_uid, unused_umask, unused_start_new_session, unused_process_group)
   1536 # Start the process
   1537 try:
-> 1538     hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1539                              # no special security
   1540                              None, None,
   1541                              int(not close_fds),
   1542                              creationflags,
   1543                              env,
   1544                              cwd,
   1545                              startupinfo)
   1546 finally:
   1547     # Child is launched. Close the parent's copy of those pipe
   1548     # handles that only the child should have open.  You need
   (...)
   1551     # pipe will not close when the child process exits and the
   1552     # ReadFile will hang.
   1553     self._close_pipe_fds(p2cread, p2cwrite,
   1554                          c2pread, c2pwrite,
   1555                          errread, errwrite)

FileNotFoundError: [WinError 2] winerror 2 the system cannot find the file specified.

please help me,I really appreciate that! I don't know how to fix it,so I just look for help.

0 Answers0