在项目中配置uv:
转载自知乎:https://zhuanlan.zhihu.com/p/27261492165
下载uv: 不推荐用pip(会出现找不到的情况). 用官方提供的加载脚本:官方uv安装方法
假定你的项目为 project/ 首先, 将UV_CACHE_DIR环境变量设置为你想要的路径.
然后直接 uv init –python 3.11. 非常推荐带上python, 不然容易导致uv找到一个错误的python解析器(你永远不知道你的PATH里藏了什么垃圾)
接着 uv add -r requirements.txt. 立刻就完成pip项目的迁移了. 仔细观察你会发现pyproject文件也已经一并更新! 之后你只需要无脑uv add即可.
运行程序: 忘掉python, 使用uv run. 值得一提的是, 官网在这里写的非常不明确, 但是经过我多方查证, uv run是会自动将你的代码隔离到虚拟环境中的, 而uv venv只是创建虚拟环境, 如果你已经有一个.venv, 它会反过来清空. 所以其实我建议你就当不存在uv venv这个命令, uv run非常智能.
uv run的这种隔离性质导致它非常适合进行一些测试, 你可以直接写uv run script.py –with your_lib, 不需要手动去先下载your_lib.
最后小记一下uv的Cache机制. uv会在cache目录下保存真实文件, 而venv全是硬链接. 这也要求cache目录必须和venv在同一个文件系统上, 否则, 按照uv官方的说法, 将会触发copy(导致降速和重复文件).
对我来说uv最让我满意的地方就是自动依赖管理和包重用
精选其它uv教程:
uv中文文档网站:https://hellowac.github.io/uv-zh-cn/reference/cli/
Python 新一代包管理工具 `uv`:从入门到进阶:https://blog.csdn.net/sinat_37574187/article/details/145644999
http://wish-club.ru/forums/index.php?autocom=gallery&req=si&img=5239
http://toyota-porte.ru/forums/index.php?autocom=gallery&req=si&img=3277
https://vitz.ru/forums/index.php?autocom=gallery&req=si&img=4833
https://myteana.ru/forums/index.php?autocom=gallery&req=si&img=6837
https://hrv-club.ru/forums/index.php?autocom=gallery&req=si&img=7092
http://wish-club.ru/forums/index.php?autocom=gallery&req=si&img=5354
http://terios2.ru/forums/index.php?autocom=gallery&req=si&img=4687
https://vitz.ru/forums/index.php?autocom=gallery&req=si&img=4839
https://honda-fit.ru/forums/index.php?autocom=gallery&req=si&img=7103