0
我在python腳本中使用pip模塊來自動安裝軟件/模塊。我該如何檢查(遠程)軟件/模塊是否存在?我沒有發現任何可以做到這一點的pip模塊。Python3 pip模塊,檢查軟件包是否存在PyPi
我的代碼:
class install_pip:
def __init__(self):
self._liste=['install']
def install(self):
pip.main(self._liste)
def addsoftware(self, software):
if type(software) is str:
self._liste.append(software)
if type(software) is list:
for i in software:
self._liste.append(i)
def delsoftware(self, software):
if type(software) is str:
self._liste.remove(software)
if type(software) is list:
for i in software:
self._liste.remove(i)
def _return(self):
return self._liste[1:len(self._liste)]
list = property(_return)
我要檢查,如果 '軟件' 存在。 謝謝。
編輯:我想這個代碼:
try:
pip.main(['install', 'nonexistentpackage'])
except pip.InstallationError as err:
print(echec)
但我沒有得到任何錯誤...
謝謝,但如果遠程包存在,有沒有訪問的安裝軟件的緩存Python化的方式,不考? –