在python脚本中安装ubuntu软件包

米拉德

我想在我的python脚本中安装以下软件包:

python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 
python-magic python-gridfs python-libvirt python-bottle python-pefile
python-chardet git build-essential autoconf automake libtool dh-autoreconf 
libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox 
dkms python-pyrex

我已经编写了以下代码,但无法正常工作。我怎么解决这个问题?

    self.command = "apt install"
    self.packages = "python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 python-magic python-gridfs python-libvirt python-bottle python-pefile python-chardet git build-essential autoconf automake libtool dh-autoreconf libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox dkms python-pyrex"

    print("[+] Installation of the ubuntu packages is starting:")
    for items in packages:
        subprocess.run(str(command.split()) + str(items), stdout=DEVNULL, stderr=DEVNULL)
        print("\[+] Package {} Installed".format(str(self.items)))
塞尔吉(Sergiy Kolodyazhnyy)

您那里有几个问题:

  • 你失踪selffor items in packages:
  • self.packages是一个字符串,当您调用for item self.packages时,将迭代该字符串的每个字符。您应该从一开始就将软件包声明为列表,或者.split()在末尾添加软件包
  • self.packages长,不符合每行79个字符的PEP8标准。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章