我想知道是否可能在尝试导入模块之前使用我的Python脚本安装模块。现在运行脚本时,它会尝试导入模块(当然),但我希望它安装模块,然后检查是否可以导入它。
更新1
这是我想要在运行脚本时使用的安装脚本:
def install():
print("\nChecking for dependencies, please stand by...")
with hideInfo():
if str(os.name) == 'nt':
easy_install.main(['textract'])
pip.main(['install', 'logging'])
pip.main(['install', 'datetime'])
else:
pip.main(['install', 'textract'])
pip.main(['install', 'logging'])
pip.main(['install', 'datetime'])
time.sleep(1)
menu()