使用python的subprocess调用系统命令的时候会报错
例如:
e[2Kfq_sub | File “/app/custom_utils.py”, line 15, in find_pids_by_port
e[2Kfq_sub | process = await asyncio.create_subprocess_exec(
e[2Kfq_sub | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e[2Kfq_sub | File “/usr/local/lib/python3.11/asyncio/subprocess.py”, line 223, in create_subprocess_exec
e[2Kfq_sub | transport, protocol = await loop.subprocess_exec(
e[2Kfq_sub | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
e[2Kfq_sub | File “/usr/local/lib/python3.11/asyncio/base_events.py”, line 1708, in subprocess_exec
e[2Kfq_sub | transport = await self._make_subprocess_transport(
e[2Kfq_sub | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e[2Kfq_sub | File “/usr/local/lib/python3.11/asyncio/unix_events.py”, line 207, in _make_subprocess_transport
e[2Kfq_sub | transp = _UnixSubprocessTransport(self, protocol, args, shell,
e[2Kfq_sub | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
e[2Kfq_sub | File “/usr/local/lib/python3.11/asyncio/base_subprocess.py”, line 36, in init
e[2Kfq_sub | self._start(args=args, shell=shell, stdin=stdin, stdout=stdout,
e[2Kfq_sub | File “/usr/local/lib/python3.11/asyncio/unix_events.py”, line 818, in _start
e[2Kfq_sub | self._proc = subprocess.Popen(
e[2Kfq_sub | ^^^^^^^^^^^^^^^^^
e[2Kfq_sub | File “/usr/local/lib/python3.11/subprocess.py”, line 1026, in init
e[2Kfq_sub | self._execute_child(args, executable, preexec_fn, close_fds,
e[2Kfq_sub | File “/usr/local/lib/python3.11/subprocess.py”, line 1955, in _execute_child
e[2Kfq_sub | raise child_exception_type(errno_num, err_msg, err_filename)
e[2Kfq_sub | FileNotFoundError: [Errno 2] No such file or directory: ‘lsof’
系统里很明显是不可能没lsof命令的,但是在环境中无法调用,不知道是否要手动指定lsof的位置才可以调用成功还是因为其他bug?还有python环境怎么换源?
谨防还有和我一样的小白踩坑,1panel的python环境是靠docker容器拉取的,创建容器的时候并不会编译其他环境进去。所以如果需要调用linux命令的subprocess,只需要在启动命令前面加上例如:apt-get update && apt-get install -y lsof 手动安装好环境就行了