Open1
Rye(uv)で気になったライブラリを試すときにプロジェクトディレクトリ名をそのライブラリ名にしてはいけない

ディレクトリ構成 & 環境
hoge
└── learn
├── python
├── java
└── ...
$ rye --version
rye 0.38.0
commit: 0.38.0 (3e3c8540f 2024-08-02)
platform: windows (x86_64)
self-python: cpython@3.12.3
symlink support: true
uv enabled: true
経緯
loguru
というロギングライブラリが気になったので遊んでみようと、
cd hoge/learn/python/
mkdir loguru
cd loguru
rye init
と下準備して。
rye add loguru
とすると、
$ rye add loguru
Initializing new virtualenv in learn\python\loguru\.venv
Python version: cpython@3.12.3
Added loguru>=0.7.2 as regular dependency
Reusing already existing virtualenv
Generating production lockfile: learn\python\loguru\requirements.lock
× No solution found when resolving dependencies:
╰─▶ Because only loguru<0.7.2 is available and you require loguru>=0.7.2, we can conclude that the requirements are unsatisfiable.
error: could not write production lockfile for project
Caused by:
Failed to run uv compile requirements.txt. uv exited with status: exit code: 1
となって、うまくいかない。
原因
pyproject.toml
[project]
name = "loguru"
version = "0.1.0"
description = "Add your description here"
authors = [
]
dependencies = [
"loguru>=0.7.2",
]
readme = "README.md"
requires-python = ">= 3.8"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.rye]
managed = true
dev-dependencies = []
[tool.hatch.metadata]
allow-direct-references = true
[tool.hatch.build.targets.wheel]
packages = ["src/loguru"]
を見ると、
[project]
name = "loguru"
version = "0.1.0"
とある。
おそらくここが競合してしまい、$ rye add loguru
がうまくいかないと考えらえる。
結論
learn/python/try-loguru
とか learn/python/loguru-tutorial
とかにすれば回避できる。