You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Ubuntu 23.10下安全安装Python 3.9+(含pip、venv)及解决依赖冲突问题的求助

Ubuntu 23.10下安全安装Python 3.9+(含pip、venv)及解决依赖冲突问题的求助

大家好,我刚把Ubuntu从20.04升级到23.10,之前第一次用Ubuntu搞Python开发时踩了坑,不得不重装系统。现在想找个安全靠谱的方法安装Python 3.9及以上版本(我偏好使用新版本),还要确保pip、venv这些开发必需工具都能正常使用,而且绝对不能搞坏系统里的其他程序。

先跟大家说说我目前的情况和遇到的问题:

  • 系统默认状态:升级到23.10后,系统默认的Python包是3.12,但我完全没手动安装过任何Python版本,VSCode却显示出4个不同的Python解释器:
    VSCode显示的Python解释器列表

  • 已执行的操作和报错:

    1. 我执行了sudo apt install python3-pip,成功安装了pip,现在运行pip3 --version的输出是:
      ashish@ashish-pc:~$ pip3 --version
      pip 23.1.2 from /usr/lib/python3/dist-packages/pip (python 3.11)
      
    2. 尝试安装venv时遇到了依赖冲突,执行sudo apt-get update && sudo apt-get install python3-venv后得到如下错误:
      Hit:1 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic InRelease
      Hit:2 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-updates InRelease
      Hit:3 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-backports InRelease
      Hit:4 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu mantic-security InRelease
      Hit:5 https://dl.google.com/linux/chrome/deb stable InRelease                  
      Hit:6 https://packages.microsoft.com/repos/code stable InRelease               
      Hit:7 http://archive.ubuntu.com/ubuntu mantic InRelease                        
      Hit:8 http://archive.ubuntu.com/ubuntu mantic-updates InRelease                
      Hit:9 http://security.ubuntu.com/ubuntu mantic-security InRelease
      Reading package lists... Done
      Reading package lists... Done
      Building dependency tree... Done
      Reading state information... Done
      Some packages could not be installed. This may mean that you have
      requested an impossible situation or if you are using the unstable
      distribution that some required packages have not yet been created
      or been moved out of Incoming.
      The following information may help to resolve the situation:
      
      The following packages have unmet dependencies:
       python3-venv : Depends: python3.11-venv (>= 3.11.2-1~) but it is not going to be installed
                       Depends: python3 (= 3.11.2-1) but 3.11.4-5 is to be installed
      E: Unable to correct problems, you have held broken packages.
      
    3. 我偶然发现python -m venv命令似乎存在,但不确定它能不能正常创建虚拟环境。

我的核心需求总结:

  • 安全安装Python 3.9及以上版本(优先最新版),绝对不能破坏系统原有程序
  • 确保pip、venv等开发工具能正常工作,没有依赖问题
  • 搞清楚为什么VSCode会显示多个我没手动安装的解释器,以及如何处理这种情况

希望有经验的朋友能给我一些指导,谢谢大家!

备注:内容来源于stack exchange,提问作者Ashish Agarwal

火山引擎 最新活动