使用subprocess.py报in __init__ restore_signals, start_new_session的错误

博主的Python代码重装系统后无法运行,网上搜索无果。后看到英文帖子提示,想起代码中Popen里的cmd要执行FFmpeg命令,而重装系统后未配置FFmpeg环境变量。关闭编辑器,配置环境变量后代码正常运行。

使用subprocess.py报in __init__ restore_signals, start_new_session的错误


今天在运行Python代码的时候遇到subprocess.py报错:

File "D:\code\video.py", line 76, in _parse_infos
    proc = sp.Popen(cmd, **popen_params)
File "D:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "D:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

这个错误很诡异,因为这个Python代码我之前是可以正常运行的,但是重装系统后就不能了,在网上搜了半天也没搜到有用的信息。后来无意中看到一个英文帖子说,检查一下Popen里面的cmd是否可以正常运行,我突然想起来这个cmd里面是要执行FFmpeg命令的,但是重装系统后环境变量还没配置。于是关闭编辑器,配置FFmpeg的环境变量,然后就可以正常运行了。

TrackCpuLoad.py:21: UserWarning: Glyph 26102 (\N{CJK UNIFIED IDEOGRAPH-65F6}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 31186 (\N{CJK UNIFIED IDEOGRAPH-79D2}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 20351 (\N{CJK UNIFIED IDEOGRAPH-4F7F}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 29992 (\N{CJK UNIFIED IDEOGRAPH-7528}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 30417 (\N{CJK UNIFIED IDEOGRAPH-76D1}) missing from current font. plt.tight_layout() TrackCpuLoad.py:21: UserWarning: Glyph 25511 (\N{CJK UNIFIED IDEOGRAPH-63A7}) missing from current font. plt.tight_layout() Traceback (most recent call last): File "TrackCpuLoad.py", line 29, in <module> text=True File "C:\Users\W8097801\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 800, in __init__ restore_signals, start_new_session) File "C:\Users\W8097801\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1207, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 系统找不到指定的文件。
最新发布
12-04
FileNotFoundError Traceback (most recent call last) <ipython-input-7-77a68b487be5> in <module>() 13 # 创建 SparkConf 和 SparkContext 14 conf = SparkConf().setAppName("ConnectionTest").setMaster("local[*]") ---> 15 sc = SparkContext(conf=conf) 16 17 # 进行简单的测试 C:\ProgramData\Anaconda3\lib\site-packages\pyspark\context.py in __init__(self, master, appName, sparkHome, pyFiles, environment, batchSize, serializer, conf, gateway, jsc, profiler_cls) 142 " is not allowed as it is a security risk.") 143 --> 144 SparkContext._ensure_initialized(self, gateway=gateway, conf=conf) 145 try: 146 self._do_init(master, appName, sparkHome, pyFiles, environment, batchSize, serializer, C:\ProgramData\Anaconda3\lib\site-packages\pyspark\context.py in _ensure_initialized(cls, instance, gateway, conf) 337 with SparkContext._lock: 338 if not SparkContext._gateway: --> 339 SparkContext._gateway = gateway or launch_gateway(conf) 340 SparkContext._jvm = SparkContext._gateway.jvm 341 C:\ProgramData\Anaconda3\lib\site-packages\pyspark\java_gateway.py in launch_gateway(conf, popen_kwargs) 99 else: 100 # preexec_fn not supported on Windows --> 101 proc = Popen(command, **popen_kwargs) 102 103 # Wait for the file to appear, or for the process to exit, whichever happens first. C:\ProgramData\Anaconda3\lib\subprocess.py in __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, encoding, errors) 707 c2pread, c2pwrite, 708 errread, errwrite, --> 709 restore_signals, start_new_session) 710 except: 711 # Cleanup if the child failed starting. C:\ProgramData\Anaconda3\lib\subprocess.py in _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_start_new_session) 995 env, 996 os.fspath(cwd) if cwd is not None else None, --> 997 startupinfo) 998 finally: 999 # Child is launched. Close the parent's copy of those pipe FileNotFoundError: [WinError 2] 系统找不到指定的文件。
11-25
--------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) ~/miniconda3/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex, cwd) 232 try: --> 233 report = subprocess.check_output( 234 command, cwd=cwd if cwd is not None else self.texcache, ~/miniconda3/lib/python3.8/subprocess.py in check_output(timeout, *popenargs, **kwargs) 414 --> 415 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, 416 **kwargs).stdout ~/miniconda3/lib/python3.8/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs) 492 --> 493 with Popen(*popenargs, **kwargs) as process: 494 try: ~/miniconda3/lib/python3.8/subprocess.py in __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, encoding, errors, text) 857 --> 858 self._execute_child(args, executable, preexec_fn, close_fds, 859 pass_fds, cwd, env, ~/miniconda3/lib/python3.8/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session) 1703 err_msg = os.strerror(errno_num) -> 1704 raise child_exception_type(errno_num, err_msg, err_filename) 1705 raise child_exception_type(err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'latex' The above exception was the direct cause of the following exception: RuntimeError Traceback (most recent call last) ~/miniconda3/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj) 339 pass 340 else: --> 341 return printer(obj) 342 # Finally look for special method names 343 method = get_real_method(obj, self.print_method) ~/miniconda3/lib/python3.8/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, base64, **kwargs) 149 FigureCanvasBase(fig) 150 --> 151 fig.canvas.print_figure(bytes_io, **kw) 152 data = bytes_io.getvalue() 153 if fmt == 'svg': ~/miniconda3/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs) 2288 ) 2289 with getattr(renderer, "_draw_disabled", nullcontext)(): -> 2290 self.figure.draw(renderer) 2291 2292 if bbox_inches: ~/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs) 71 @wraps(draw) 72 def draw_wrapper(artist, renderer, *args, **kwargs): ---> 73 result = draw(artist, renderer, *args, **kwargs) 74 if renderer._rasterizing: 75 renderer.stop_rasterizing() ~/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer) 48 renderer.start_filter() 49 ---> 50 return draw(artist, renderer) 51 finally: 52 if artist.get_agg_filter() is not None: ~/miniconda3/lib/python3.8/site-packages/matplotlib/figure.py in draw(self, renderer) 2801 2802 self.patch.draw(renderer) -> 2803 mimage._draw_list_compositing_images( 2804 renderer, self, artists, self.suppressComposite) 2805 ~/miniconda3/lib/python3.8/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite) 130 if not_composite or not has_images: 131 for a in artists: --> 132 a.draw(renderer) 133 else: 134 # Composite any adjacent images together ~/miniconda3/lib/python3.8/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer) 48 renderer.start_filter() 49 ---> 50 return draw(artist, renderer) 51 finally: 52 if artist.get_agg_filter() is not None: ~/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in draw(self, renderer) 3044 artists.remove(spine) 3045 -> 3046 self._update_title_position(renderer) 3047 3048 if not self.axison: ~/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py in _update_title_position(self, renderer) 2994 _log.debug('top of Axes not in the figure, so title not moved') 2995 return -> 2996 if title.get_window_extent(renderer).ymin < top: 2997 _, y = self.transAxes.inverted().transform((0, top)) 2998 title.set_position((x, y)) ~/miniconda3/lib/python3.8/site-packages/matplotlib/text.py in get_window_extent(self, renderer, dpi) 908 909 with cbook._setattr_cm(self.figure, dpi=dpi): --> 910 bbox, info, descent = self._get_layout(self._renderer) 911 x, y = self.get_unitless_position() 912 x, y = self.get_transform().transform((x, y)) ~/miniconda3/lib/python3.8/site-packages/matplotlib/text.py in _get_layout(self, renderer) 307 308 # Full vertical extent of font, including ascenders and descenders: --> 309 _, lp_h, lp_d = renderer.get_text_width_height_descent( 310 "lp", self._fontproperties, 311 ismath="TeX" if self.get_usetex() else False) ~/miniconda3/lib/python3.8/site-packages/matplotlib/backends/backend_agg.py in get_text_width_height_descent(self, s, prop, ismath) 257 texmanager = self.get_texmanager() 258 fontsize = prop.get_size_in_points() --> 259 w, h, d = texmanager.get_text_width_height_descent( 260 s, fontsize, renderer=self) 261 return w, h, d ~/miniconda3/lib/python3.8/site-packages/matplotlib/texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer) 333 if tex.strip() == '': 334 return 0, 0, 0 --> 335 dvifile = self.make_dvi(tex, fontsize) 336 dpi_fraction = renderer.points_to_pixels(1.) if renderer else 1 337 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi: ~/miniconda3/lib/python3.8/site-packages/matplotlib/texmanager.py in make_dvi(self, tex, fontsize) 269 # not support.) 270 with TemporaryDirectory(dir=Path(dvifile).parent) as tmpdir: --> 271 self._run_checked_subprocess( 272 ["latex", "-interaction=nonstopmode", "--halt-on-error", 273 f"../{texfile.name}"], tex, cwd=tmpdir) ~/miniconda3/lib/python3.8/site-packages/matplotlib/texmanager.py in _run_checked_subprocess(self, command, tex, cwd) 235 stderr=subprocess.STDOUT) 236 except FileNotFoundError as exc: --> 237 raise RuntimeError( 238 'Failed to process string with tex because {} could not be ' 239 'found'.format(command[0])) from exc RuntimeError: Failed to process string with tex because latex could not be found
08-13
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值