使用uv安装python任意版本的命令详解(uv python install)
更新时间:2025年08月27日 10:50:25 作者:skywalk8163
uv是一个超快速的Python包安装器和解析器,用Rust编写,是pip、pip-tools和virtualenv的高速替代品,这篇文章主要介绍了使用uv安装python任意版本命令(uv python install)的相关资料,需要的朋友可以参考下
使用uv安装python任意版本
先使用uv看看可以装哪些版本
输出:
uv python list cpython-3.14.0a5+freethreaded-linux-x86_64-gnu <download available> cpython-3.14.0a5-linux-x86_64-gnu <download available> cpython-3.13.2+freethreaded-linux-x86_64-gnu <download available> cpython-3.13.2-linux-x86_64-gnu <download available> cpython-3.12.9-linux-x86_64-gnu py312/bin/python3.12 cpython-3.12.9-linux-x86_64-gnu py312/bin/python3 -> python3.12 cpython-3.12.9-linux-x86_64-gnu py312/bin/python -> python3.12 cpython-3.12.9-linux-x86_64-gnu <download available> cpython-3.11.11-linux-x86_64-gnu <download available> cpython-3.10.16-linux-x86_64-gnu <download available> cpython-3.10.12-linux-x86_64-gnu /usr/bin/python3.10 cpython-3.10.12-linux-x86_64-gnu /usr/bin/python3 -> python3.10 cpython-3.10.12-linux-x86_64-gnu /bin/python3.10 cpython-3.10.12-linux-x86_64-gnu /bin/python3 -> python3.10 cpython-3.9.21-linux-x86_64-gnu <download available> cpython-3.8.20-linux-x86_64-gnu <download available> cpython-3.7.9-linux-x86_64-gnu <download available> pypy-3.11.11-linux-x86_64-gnu <download available> pypy-3.10.19-linux-x86_64-gnu <download available> pypy-3.9.19-linux-x86_64-gnu <download available> pypy-3.8.16-linux-x86_64-gnu <download available> pypy-3.7.13-linux-x86_64-gnu <download available>
安装python3.9版本
uv python install 3.9
速度有点慢...安装完成,用uv python list来看一下:
cpython-3.9.21-linux-x86_64-gnu /home/skywalk/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/bin/python3.9
临时添加到路径
# 临时添加路径(关闭终端后失效) export PATH="$HOME/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/bin:$PATH" # 验证 python --version #
好的,证明现在就是python3.9了:
python --version # Python 3.9.21
永久添加到 PATH
- 步骤:编辑
~/.bashrc、~/.zshrc或~/.bash_profile: echo 'export PATH="$HOME/.local/share/uv/python/3.10.12/bin:$PATH"' >> ~/.bashrc
执行
source ~/.bashrc生效
不行,换方法
创建python3.9虚拟环境
uv venv py39 source py39/bin/activate
还是不行
现在只能用这个方法,加参数:--break-system-packages
pip install pip -U --break-system-packages
测试的时候这样用
安装测试库
pip install -e ".[testing]" --break-system-packages
测试
pytest
调试
pip install的时候报错This Python installation is managed by uv and should not be modified.
pip install -e ".[testing]" [notice] A new release of pip is available: 24.3.1 -> 25.1.1 [notice] To update, run: pip install --upgrade pip error: externally-managed-environment × This environment is externally managed ╰─> This Python installation is managed by uv and should not be modified. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
搞不定,只好创建虚拟环境
uv venv py39 source py39/bin/activate
uv venv py39 Using CPython 3.9.21 Creating virtual environment at: py39 Activate with: source py39/bin/activate (base) skywalk@ubuntu22win:~$ source py39/bin/activate
总结
到此这篇关于使用uv安装python任意版本命令的文章就介绍到这了,更多相关uv安装python任意版本命令内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
详解python3中用HTMLTestRunner.py报ImportError: No module named ''
这篇文章主要介绍了详解python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决,感兴趣的可以了解一下2019-08-08
解读torch.cuda.amp自动混合精度训练之节省显存并加快推理速度
这篇文章主要介绍了torch.cuda.amp自动混合精度训练之节省显存并加快推理速度问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2023-08-08
python之PyInstaller(将Python脚本打包为可执行文件方式)
PyInstaller将Python脚本打包为跨平台可执行文件,自动处理依赖库,支持单文件/目录模式,便于分发,适用于GUI、数据文件处理及多平台部署,优化体积与权限问题2025-09-09


最新评论