繁体   English   中英

有条件地在 Google Colab 上安装 Python 包

[英]Conditionally install a Python package on Google Colab

在 Google Colab 上,每次关闭运行时,我都需要重新安装一些 Python 包。 这可能不是很愉快。

如何有条件地安装这些软件包?

好吧,这段代码工作得很好:

# 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM