【问题标题】:WSL2: Python rename files from with VS Code debuggerWSL2:Python 使用 VS Code 调试器重命名文件
【发布时间】:2021-04-04 11:22:52
【问题描述】:

我将 WSL2 与带有 conda 包管理器的 Ubuntu 发行版一起使用。我可以使用 Visual Studio Code GUI(由 code . 在 WSL Ubuntu 终端中启动)在 Windows 上读取和编辑文件(通过 /mnt/c 访问)。

我有以下脚本,我试图从所有 pdf 文件的名称中删除空格:

import os
fldr = '/mnt/c/Documents and Settings/Lenovo/Desktop/'
for f in os.listdir(fldr):
    if 'pdf' in f:
        print(f)
        os.rename(fldr+f, fldr+f.replace(' ','_'))
        print(f.replace(' ','_'))

如果我通过调试器 (F5) 运行脚本,我会收到权限错误 [Errno 13]

如果我使用调试器创建的终端使用 Python 代码手动重命名,我不会收到权限错误。

【问题讨论】:

    标签: python visual-studio-code windows-subsystem-for-linux remote-debugging


    【解决方案1】:

    我很确定运行调试器(在您的窗口中运行)的用户和在 WSL 中运行的用户之间存在差异。

    尝试运行以下命令将用户名设置为与 windows 相同:

    wsl --user <your username>
    

    【讨论】:

      猜你喜欢
      • 2020-12-16
      • 2021-08-18
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多