os.chdir()命令报错:FileNotFoundError:[Errno 2] 没有该文件或目录:'C:\\Users在Jupyter笔记中没有b'

2024-03-29 11:19:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Jupyter笔记本,并试图将当前工作目录更改为我的系统目录,即“C:/Users”,但它给了我一个错误:FileNotFoundError:[Errno 2]没有这样的文件或目录:“C://Users”。 然而,同样的方法在空闲状态下也能正常工作。请帮忙。在

这是在朱皮特笔记本里试过的

```import os
cwd = os.getcwd()
files = os.listdir(cwd)
os.chdir("C://Users")
os.getcwd()

-----------------------------------------------------------
FileNotFoundError        Traceback (most recent call last)
<ipython-input-16-03f5279edef8> in <module>
      2 cwd = os.getcwd()
      3 files = os.listdir(cwd)
----> 4 os.chdir("C://Users")
      5 os.getcwd()

FileNotFoundError: [Errno 2] No such file or directory: 'C://Users'
```

Tags: 文件目录os错误笔记本jupyterfilesusers