如何使用 Google Colab 中的需求文件安装 python 依赖项?
相当于
pip install -r requirements.txt
根据上面丹尼尔的提示,我能够解决它。
使用“从本地计算机脚本上传文件”我将我的requirements.txt文件上传到Google Colab平台。脚本可在here找到。这是剧本
from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
print('User uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
执行时的输出清楚地表明,它正在将此文件保存为“requirements.txt”。不过我在 Google Drive 中找不到这个文件,这对我来说没问题。然后,
!pip install -r requirements.txt
成功了!
您可以使用 IPython 魔法函数
%%writefile
编写文件,然后只需执行 !pip install -r requirements.txt
即:
单元1
%%writefile requirements.txt
<contents of your requiements.txt>
细胞2
!pip install -r requirements.txt
您在 Google 云端硬盘中找不到上传的文件。因为它是在Python 3 Google后端计算引擎中上传的。当您终止会话时,所有文件和数据都将被删除。
尝试;
python -m pip install -r requirements.txt
你可以使用
pip install -r"path"