简体   繁体   English

Python 3.9.6 - subprocess.run - subprocess.CalledProcessError:命令 pip 安装 pkg 返回非零退出状态 1

[英]Python 3.9.6 - subprocess.run - subprocess.CalledProcessError: Command pip install pkg returned non-zero exit status 1

Python 3.9.6 - subprocess.run - subprocess.CalledProcessError: Command '['/opt/disk1/apps/venv_test/bin/python', '-m', 'pip', 'install pkg', '-q']' returned non-zero exit status 1. Python 3.9.6 - subprocess.run - subprocess.CalledProcessError:命令'['/opt/disk1/apps/venv_test/bin/python','-m','pip','install pkg','-q'] ' 返回非零退出状态 1。

Using Python 3.9.6, unable to get the below code executed and its throwing error for --pkg-- package.使用 Python 3.9.6 时,无法执行以下代码并抛出 --pkg-- package 错误。 Error is given at below.错误如下。

However, when trying to run the same command manually on linux console但是,当尝试在 linux 控制台上手动运行相同的命令时

command -> /opt/disk1/apps/venv_test/bin/python -m pip install pkg -q

then然后

  • this manual execution completed successfully此手动执行成功完成
  • --pkg-- package got installed as well and --pkg-- package 也已安装,并且
  • after this manual execution, when trying to execute below piece of code then its not throwing this or any other error as well在此手动执行之后,当尝试执行以下代码时,它也不会抛出此错误或任何其他错误

*Please advice why the code is not able to get executed without installing pkg manually? *请告知为什么如果不手动安装 pkg 代码无法执行?

Let me know if any additional info is required along with way to get this please.*让我知道是否需要任何其他信息以及获取此信息的方法。*

Code giving this error ->给出此错误的代码 ->

  packages = ['fileinput', 'glob', 'gzip', 'hashlib', 'json', 'paramiko', 'pkg', 'psutil', 're', 'requests',
              'shutil',
              'socket']
  [subprocess.run([sys.executable, '-m', 'pip', 'install ' + pckg, '-q'], check=True) for pckg in packages if
   not importlib.util.find_spec(pckg)]

Error: -错误: -

ERROR: unknown command "install pkg" - maybe you meant "install"

Traceback (most recent call last):
  File "/opt/disk1/apps/bookcomponents.py", line 653, in <module>
    get_configurations_and_extract_info(redownload=False, kill_restart_required=True,
  File "/opt/disk1/apps/bookcomponents.py", line 504, in get_configurations_and_extract_info
    [subprocess.run([sys.executable, '-m', 'pip', 'install ' + pckg, '-q'], check=True) for pckg in packages if
  File "/opt/disk1/apps/bookcomponents.py", line 504, in <listcomp>
    [subprocess.run([sys.executable, '-m', 'pip', 'install ' + pckg, '-q'], check=True) for pckg in packages if
  File "/usr/lib64/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/opt/disk1/apps/venv_test/bin/python', '-m', 'pip', 'install pkg', '-q']' returned non-zero exit status 1.
(venv_test) [login@server:/opt/disk1/apps/Book/05Aug2022]$  pip list | grep pkg
WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
You should consider upgrading via the '/opt/disk1/apps/venv_test/bin/python3 -m pip install --upgrade pip' command.
(venv_test) [login@server:/opt/disk1/apps/Book/05Aug2022]$  python --version
Python 3.9.6

You shouldn't concatenate the package name with the install keyword.您不应将 package 名称与install关键字连接。 You're executing你在执行

php -m pip 'install fileinput' -q

instead of代替

php -m pip install fileinput -q

install and pckg should be separate arguments, not a single concatenated string. installpckg应该是单独的 arguments,而不是单个连接的字符串。

  [subprocess.run([sys.executable, '-m', 'pip', 'install', pckg, '-q'], check=True) for pckg in packages if
    not importlib.util.find_spec(pckg)]

BTW, it's not pythonic to use a list comprehension if you're not doing anything with the resulting list.顺便说一句,如果您没有对结果列表做任何事情,那么使用列表理解并不是 Pythonic。 Use an ordinary for loop.使用普通for循环。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python subprocess.CalledProcessError:返回非零退出状态 2 - Python subprocess.CalledProcessError: returned non-zero exit status 2 Python subprocess.CalledProcessError:命令&#39;adb设备&#39;返回非零退出状态127 - Python subprocess.CalledProcessError: Command 'adb devices' returned non-zero exit status 127 subprocess.CalledProcessError: ...返回非零退出状态 255 - subprocess.CalledProcessError: ... returned non-zero exit status 255 subprocess.CalledProcessError:返回非零退出状态0 - subprocess.CalledProcessError: returned non-zero exit status 0 subprocess.CalledProcessError返回非零退出状态1 - subprocess.CalledProcessError returned non-zero exit status 1 "subprocess.CalledProcessError:命令“df”返回非零退出状态 1" - subprocess.CalledProcessError: Command 'df' returned non-zero exit status 1 Python:wifi subprocess.CalledProcessError:命令'['/ sbin / ifdown','wlp4s0']'返回非零退出状态1 - Python: wifi subprocess.CalledProcessError: Command '['/sbin/ifdown', 'wlp4s0']' returned non-zero exit status 1 运行Python Cookiecutter以从GitHub中获取模板的结果为subprocess.CalledProcessError,返回非零退出状态128 - Running Python Cookiecutter to get template from GitHub results in subprocess.CalledProcessError, returned non-zero exit status 128 subprocess.CalledProcessError:返回非零退出状态 1,而 os.system 不会引发任何错误 - subprocess.CalledProcessError: returned non-zero exit status 1, while os.system does not raise any error subprocess.CalledProcessError…返回非零退出状态2 - subprocess.CalledProcessError… returns non zero exit status 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM