在 Google Colab 上,每次关闭运行时,我都需要重新安装一些 Python 包。这可能不是很愉快。
如何有条件地安装这些软件包?
回答1
好吧,这段代码工作得很好:
# conditional install yahoo_fin
try:
import yahoo_fin.stock_info as si
except ModuleNotFoundError:
if 'google.colab' in str(get_ipython()):
%pip install yahoo_fin
import yahoo_fin.stock_info as si