我想在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)))发布于 2016-07-25 00:22:41
你在这里有几个问题:
self in for items in packages:self.packages是一个字符串,当您调用for item self.packages时,它会迭代该字符串的每个字符。您应该从一开始就将包声明为list,或者在末尾添加.split()。self.packages很长,不符合每行79个字符的PEP8标准。发布于 2016-07-24 20:08:34
固定:
def package_installation(self):
self.apt = "apt "
self.ins = "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"
self.color.print_green("[+] Installation of the ubuntu packages is starting:")
for self.items in self.packages.split():
self.command = str(self.apt) + str(self.ins) + str(self.items)
subprocess.run(self.command.split())
self.color.print_blue("\t[+] Package [{}] Installed".format(str(self.items)))https://askubuntu.com/questions/802461
复制相似问题