开发者

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

开发者 https://www.devze.com 2025-09-03 09:20 出处:网络 作者: skywalk8163
目录先使用uv看看可以装哪些版本安装python3.9版本临时添加到路径永久添加到 PATH‌ 创建python3.9虚拟环境测试的时候这样用调试pip install的时候报错This Python installation is managed by uv and shou
目录
  • 先使用uv看看可以装哪些版本
  • 安装python3.9版本
    • 临时添加到路径
    • 永久添加到 PATH‌
  •  创建python3.9虚拟环境
    • 测试的时候这样用
      • 调试
        • pip install的时候报错This Python installation is managed by uv and should not be modified.
      • 总结 

        使用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                   py312js/bin/python -> python3.12
        cpython-3.12.9-linpythonux-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-android3.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 生效js

        不行,换方法

         创建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任意版本命令内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!

        0

        精彩评论

        暂无评论...
        验证码 换一张
        取 消

        关注公众号