背景简介
执行 poetry install 指令报错 The current project could not be installed: No file/folder found for package XXX
报错信息
Creating virtualenv pers-website-backend-OOAazPPH-py3.13 in /Users/huaruilin/Library/Caches/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
Installing the current project: pers-website-backend (0.1.0)
Error: The current project could not be installed: No file/folder found for package pers-website-backend
If you do not want to install the current project use --no-root.
If you want to use Poetry only for dependency management but not for packaging, you can disable package mode by setting package-mode = false in your pyproject.toml file.
If you did intend to install the current project, you may need to set `packages` in your pyproject.toml file.
解决方案
核心意思是:Poetry 尝试把“当前项目本身”当成一个包安装进虚拟环境(也就是所谓的 root 包),但它在当前目录结构里找不到一个叫 pers-website-backend 的包(通常是同名目录),所以报错:没有找到这个包对应的文件或文件夹。
由于我们本身就是一个应用项目,所以可以使用以下两种方案之一来修复。
方案一 - 推荐
更新pyproject.toml: 添加 package-mode = false 后 执行 poetry install
[project]
name = "pers-website-backend"
version = "0.1.0"
description = "personal website backend"
authors = [
{name = "Henry Lin",email = "huarui.lin@outlook.com"}
]
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
]
[tool.poetry]
package-mode = false
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
- 执行 poetry install
poetry install
Installing dependencies from lock file
方案二
直接执行指令: poetry install --no-root
poetry install --no-root
Installing dependencies from lock file
以上便是本文的全部内容,感谢您的阅读,如遇到任何问题,欢迎在评论区留言讨论。