运行 pub get 时出错:无法重命名目录,因为它正在被另一个进程使用

Error when running pub get: Failed to rename directory because it was in use by another process

当我尝试在我的 dart 控制台项目中获取 beautifulsoup 的包时出现以下错误。

[scrape_3] pub get
Resolving dependencies...
+ beautifulsoup 0.0.1
Downloading beautifulsoup 0.0.1...
Failed to rename directory because it was in use by another process.
This may be caused by a virus scanner or having a file
in the directory open in another application.
exit code 1

我的pubspec.yaml文件如下:


    name: scrape_3
    description: A sample command-line application.
    # version: 1.0.0
    # homepage: https://www.example.com
    environment:
      sdk: ">=2.10.0 <3.0.0"
    
    #dependencies:
    #  path: ^1.7.0
    dev_dependencies:
      pedantic: ^1.9.0
      test: ^1.14.4
    dependencies:
      beautifulsoup: ^0.0.1
      html: ^0.13.3+3

我该如何解决这个问题?这对我来说是一个反复出现的错误,而且经常发生。

关闭电脑并在几分钟后重新启动最终成功。显然,该文件会被 VS CODE 本身使用一段时间,直接重启不起作用

我不得不关闭 VSCode,以管理员身份打开它,然后再次 运行 flutter get

作为额外的预防措施,我还确保我没有在命令行、powershell 等中使用任何 flutter/dart 工具 运行,并且没有打开文件资源管理器 windows .

如果您使用 android 工作室
1.restart你laptop/pc.
2.close 您的防病毒软件(如果存在)。
3.run android 工作室作为管理员,然后重试。

只需重置“pubspec.lock”上的更改即可。 或者干脆删除它。