You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab无法加载Google Drive中的Pickle/CSV/Excel文件

解决Colab加载Google Drive文件路径不存在的问题
  • 问题根源:你用的相对路径./content/drive/My Drive/...写错了——Colab默认的当前工作目录是/content,所以./content等价于/content/content,这个路径自然不存在。

  • 直接解决办法:用绝对路径加载
    直接使用完整的绝对路径,比如加载各类文件:

    import joblib
    import pandas as pd
    
    # 加载pickle文件
    model = joblib.load("/content/drive/My Drive/April_2023/Source_pickle_files/你的文件名.pkl")
    # 加载Excel文件
    df_excel = pd.read_excel("/content/drive/My Drive/April_2023/Source_pickle_files/你的文件名.xlsx")
    # 加载CSV文件
    df_csv = pd.read_csv("/content/drive/My Drive/April_2023/Source_pickle_files/你的文件名.csv")
    

    路径里有空格也不用担心,直接写绝对路径Python会自动处理;也可以用原始字符串避免转义问题:r"/content/drive/My Drive/..."

  • 更便捷的方式:切换工作目录
    先切换到目标文件夹,之后就可以直接用文件名加载,不用每次写长路径:

    # 用Colab魔法命令切换工作目录
    %cd "/content/drive/My Drive/April_2023/Source_pickle_files"
    
    # 直接加载文件
    model = joblib.load("你的文件名.pkl")
    df_excel = pd.read_excel("你的文件名.xlsx")
    df_csv = pd.read_csv("你的文件名.csv")
    

内容的提问来源于stack exchange,提问作者technical

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 05:27:39