在Mac OS上执行如下命令时,很意外地报错了
git clone git@github.com:fastapi/full-stack-fastapi-template.git
cd full-stack-fastapi-template/backend
uv sync
错误内容:
$ uv sync
Using CPython 3.12.5 interpreter at: /usr/local/opt/python@3.12/bin/python3.12
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Resolved 81 packages in 3ms
error: Distribution `psycopg-binary==3.2.2 @ registry+https://mirrors.cloud.tencent.com/pypi/simple/` can't be installed because it doesn't have a source distribution or wheel for the current platform
原因:
当前系统在镜像源里,没有psycopg-binary==3.2.2的安装包
(我电脑比较老,新版的psycopg不支持)
解决:
$ uv pip install "psycopg[binary]"
Resolved 3 packages in 3.26s
Prepared 1 package in 2.71s
Installed 3 packages in 5ms
+ psycopg==3.1.19
+ psycopg-binary==3.1.19
+ typing-extensions==4.12.2
可以看到支持mac11.7的psycopg最高是到3.1.19
于是只需把pyproject.toml中的版本依赖改成<3.1.20即可
- "psycopg[binary]<4.0.0,>=3.1.13",
+ "psycopg[binary]<3.1.20,>=3.1.13",
然后,再重新执行uv sync即可