繁体   English   中英

使用python-apt安装mysql-server

[英]Install mysql-server with python-apt

我有一个ubuntu服务器,我正在其中尝试使用python-apt 安装mysql-server (以及其他软件)

问题是在某些时候需要与安装程序进行交互(提供密码)。 是否可以使用python-apt 与安装程序进行交互

例:

import apt
cache = apt.cache.Cache()
cache.update()
pkg = cache['mysql-server']
pkg.mark_install()
cache.commit()

它等待用户输入而停顿

(编辑)设法使它在这篇文章之后工作

from subprocess import check_call
command = "debconf-set-selections <<< \"mysql-server mysql-server/root_password password your_password\""
check_call(command, shell=True, executable="bash")
command = "debconf-set-selections <<< \"mysql-server mysql-server/root_password_again password your_password\""
check_call(command, shell=True, executable="bash")
command = "apt install mysql-server"
check_call(command, shell=True, executable="bash")

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM