Python-强制在代码内重新安装模块

问题描述 投票:1回答:1

我正在尝试在我的代码中强制安装软件包。为此,我有这个:

import sys
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", 'JPype1==0.6.1 --force-reinstal'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'mysqlclient pymysql'])

但是,出现以下错误:

ERROR: Invalid requirement: 'JPype1==0.6.3 --force-reinstal'
subprocess.CalledProcessError: Command '[python.exe', '-m', 'pip', 'install', 'JPype1==0.6.3 --force-reinstal']' returned non-zero exit status 1.

任何人都有解决方案吗?谢谢!

python pip subprocess
1个回答
1
投票
问题是子处理要求将每个参数发送到命令时需要一个单独的参数。同样,“重新安装”拼写错误。正确的代码如下,其中每个参数都是单独的,并且错字是固定的:

import sys import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", 'JPype1==0.6.1', '--force-reinstall']) subprocess.check_call([sys.executable, "-m", "pip", "install", 'mysqlclient', 'pymysql'])

© www.soinside.com 2019 - 2024. All rights reserved.