如何在GitHub Actions中修复DVC的'FileNotFoundError'错误
问题描述
尝试将测试数据文件夹拉取到GitHub Actions容器时,出现错误:
FileNotFoundError: [Errno 2] No such file or directory
本地运行dvc checkout --relink无效,使用Gdrive作为数据仓库,服务账号登录正常,但文件不存在。询问是否可以重新推送文件并重建仓库数据。
本地dvc doctor输出
DVC version: 2.10.2 (pip) --------------------------------- Platform: Python 3.7.13 on Linux-5.15.0-1014-azure-x86_64-with-debian-bullseye-sid Supports: gdrive (pydrive2 = 1.14.0), webhdfs (fsspec = 2022.5.0), http (aiohttp = 3.8.1, aiohttp-retry = 2.5.2), https (aiohttp = 3.8.1, aiohttp-retry = 2.5.2) Cache types: <https://error.dvc.org/no-dvc-cache> Caches: local Remotes: gdrive Workspace directory: ext4 on /dev/sda1 Repo: dvc, git
本地可以克隆Git仓库并从DVC数据注册表拉取数据,但GitHub Actions中无法实现。
GitHub Actions完整回溯信息
Successfully installed PyYAML-6.0 aiohttp-3.8.1 aiohttp-retry-2.5.1 aiosignal-1.2.0 appdirs-1.4.4 async-timeout-4.0.2 asynctest-0.13.0 atpublic-2.3 attrs-21.4.0 cached-property-1.5.2 cachetools-4.2.4 certifi-2022.6.15 cffi-1.15.1 charset-normalizer-2.0.12 colorama-0.4.5 commonmark-0.9.1 configobj-5.0.6 contextvars-2.4 cryptography-37.0.4 dataclasses-0.8 decorator-4.4.2 dictdiffer-0.9.0 diskcache-5.4.0 distro-1.7.0 dpath-2.0.6 dulwich-0.20.45 dvc-2.8.1 flatten-dict-0.4.2 flufl.lock-3.2 frozenlist-1.2.0 fsspec-2022.1.0 ftfy-6.0.3 funcy-1.17 future-0.18.2 gitdb-4.0.9 gitpython-3.1.18 google-api-core-2.8.2 google-api-python-client-2.52.0 google-auth-2.9.1 google-auth-httplib2-0.1.0 googleapis-common-protos-1.56.3 grandalf-0.6 httplib2-0.20.4 idna-3.3 idna-ssl-1.1.0 immutables-0.18 importlib-metadata-4.8.3 importlib-resources-5.4.0 mailchecker-4.1.18 multidict-5.2.0 nanotime-0.5.2 networkx-2.5.1 oauth2client-4.1.3 packaging-21.3 pathspec-0.8.1 phonenumbers-8.12.52 ply-3.11 protobuf-3.19.4 psutil-5.9.1 pyOpenSSL-22.0.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycparser-2.21 pydot-1.4.2 pydrive2-1.10.1 pygit2-1.6.1 pygments-2.12.0 pygtrie-2.5.0 pyparsing-2.4.7 python-benedict-0.25.2 python-dateutil-2.8.2 python-fsutil-0.6.1 python-slugify-6.1.2 requests-2.27.1 rich-12.5.1 rsa-4.9 ruamel.yaml-0.17.21 ruamel.yaml.clib-0.2.6 shortuuid-1.0.9 shtab-1.5.5 six-1.16.0 smmap-5.0.0 tabulate-0.8.10 text-unidecode-1.3 toml-0.10.2 tqdm-4.64.0 typing-extensions-4.1.1 uritemplate-4.1.1 urllib3-1.26.10 voluptuous-0.13.1 wcwidth-0.2.5 xmltodict-0.13.0 yarl-1.7.2 zc.lockfile-2.0 zipp-3.6.0 DVC version: 2.8.1 (pip) --------------------------------- Platform: Python 3.6.15 on Linux-5.15.0-1014-azure-x86_64-with-debian-bullseye-sid Supports: gdrive (pydrive2 = 1.10.1), webhdfs (fsspec = 2022.1.0), http (aiohttp = 3.8.1, aiohttp-retry = 2.5.1), https (aiohttp = 3.8.1, aiohttp-retry = 2.5.1) Cache types: <https://error.dvc.org/no-dvc-cache> Caches: local Remotes: gdrive Workspace directory: ext4 on /dev/sdb1 Repo: dvc, git 2022-07-22 19:01:08,361 DEBUG: failed to pull cache for 'tests/data' 2022-07-22 19:01:08,364 WARNING: No file hash info found for 'tests/data'. It won't be created. 1 file failed 2022-07-22 19:01:08,365 ERROR: failed to pull data from the cloud - Checkout failed for following targets: tests/data Is your cache up to date? <https://error.dvc.org/missing-files> ------------------------------------------------------------ Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/dvc/command/data_sync.py", line 41, in run glob=self.args.glob, File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/dvc/repo/__init__.py", line 50, in wrapper return f(repo, *args, **kwargs) File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/dvc/repo/pull.py", line 44, in pull recursive=recursive, File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/dvc/repo/__init__.py", line 50, in wrapper return f(repo, *args, **kwargs) File "/opt/hostedtoolcache/Python/3.6.15/x64/lib/python3.6/site-packages/dvc/repo/checkout.py", line 110, in checkout raise CheckoutError(stats["failed"], stats) dvc.exceptions.CheckoutError: Checkout failed for following targets: tests/data Is your cache up to date? <https://error.dvc.org/missing-files> ------------------------------------------------------------ 2022-07-22 19:01:08,369 DEBUG: Analytics is enabled. 2022-07-22 19:01:08,412 DEBUG: Trying to spawn '['daemon', '-q', 'analytics', '/tmp/tmp6i9uchzh']' 2022-07-22 19:01:08,413 DEBUG: Spawned '['daemon', '-q', 'analytics', '/tmp/tmp6i9uchzh']' Error: The operation was canceled.
解决方案
1. 统一DVC版本
本地DVC版本为2.10.2,但GitHub Actions中安装的是2.8.1,版本差异可能引发兼容性问题。在GitHub Actions workflow中指定安装与本地一致的版本:
- name: Install DVC run: pip install dvc==2.10.2 dvc[gdrive]==2.10.2
2. 验证远程仓库数据完整性
本地执行dvc push tests/data,确保所有数据已推送到Gdrive远程。再运行dvc pull tests/data --dry-run,检查是否能获取到对应文件的哈希信息。
3. 重新推送并重建数据(可行方案)
确认Gdrive中数据缺失时,按以下步骤操作:
- 删除本地
.dvc/cache中对应tests/data哈希的文件/文件夹 - 重新生成测试数据文件,执行
dvc add tests/data - 运行
dvc push tests/data将新数据推送到Gdrive - 提交并推送
.dvc文件到Git仓库 - 在GitHub Actions中重新执行拉取流程
4. 检查权限配置
确保服务账号拥有Gdrive仓库的读写权限,并且在GitHub Actions workflow中正确配置了认证信息(比如通过环境变量传递服务账号密钥)。
5. 强制拉取缓存
在GitHub Actions中执行dvc pull -f tests/data,强制覆盖本地缓存并拉取最新数据。
内容的提问来源于stack exchange,提问作者Soerendip
相关产品推荐
相关产品推荐

