python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > uv安装python任意版本命令

使用uv安装python任意版本的命令详解(uv python install)

作者: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‌

不行,换方法

 创建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任意版本命令内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文