使用uv安装python任意版本,命令:uv python install
使用uv安装python任意版本
先使用uv看看可以装哪些版本
uv python list
输出:
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
:bashCopy Code
echo 'export PATH="$HOME/.local/share/uv/python/3.10.12/bin:$PATH"' >> ~/.bashrc
- 执行
source ~/.bashrc
生效
- 编辑
不行,换方法
创建python3.9虚拟环境
uv venv py39source 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 py39source 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