【问题标题】:How do I change my working directory in a proper manner? [duplicate]如何以适当的方式更改我的工作目录? [复制]
【发布时间】:2020-11-10 13:47:19
【问题描述】:

我在 Google Colab 工作,我正在尝试将工作目录更改为我的桌面(桌面 = 荷兰语中的 Bureaublad,这就是为什么您在我的路径中看到“bureaublad”)。但是,更改工作目录不断给我这样的目录不存在的错误。我只是复制了路径,所以一切都应该存在!在此处查看我的代码:

代码:

import os
print(os.getcwd())
os.listdir()

输出:

/content
['.config', 'sample_data']

代码:

os.chdir(r'C:\Users\emile\OneDrive\Bureaublad\Completed Communications Transcriptions')

输出:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-29-c4d97f3ec347> in <module>()
----> 1 os.chdir(r'C:\Users\emile\OneDrive\Bureaublad\Completed Communications Transcriptions')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\emile\\OneDrive\\Bureaublad\\Completed Communications Transcriptions'

我做错了什么?

【问题讨论】:

    标签: python google-colaboratory working-directory chdir getcwd


    【解决方案1】:

    您需要使用/ 而不是\

    import os
    os.chdir('C:/')
    

    还要检查路径是否正确,因为在您的示例中我看到的是 chdir(r'C:/') 而不是 chdir('C:/')

    【讨论】:

      【解决方案2】:

      您需要通过托管 jupyter notebook 服务器连接到本地运行时,然后输入端口号,然后您可以成功连接,如果您连接到托管运行时,您只能通过挂载它来连接到谷歌驱动器。

      更多信息可以在这里找到-Can you run Google Colab on your local computer?

      【讨论】:

      • 终于成功了!非常感谢!
      猜你喜欢
      • 2014-11-14
      • 2014-12-02
      • 2015-02-22
      • 2016-01-06
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多