[英]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然后
*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. install
和pckg
应该是单独的 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.