当前位置: 首页 > news >正文

ubuntu 安装管理多版本python3 相关问题解决

背景:使用ubuntu 22.04  默认python 未3.10.编译一些模块的时候发现需要降级到python3.9.于是下载安装

下载:

        

wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz

解压与编译

tar -xf Python-3.9.16.tgz
cd Python-3.9.16
./configure --enable-optimizations --with-lto --enable-shared
make -j4 //这里根据自己的cpu core 自行更新需要的数字 

提示:

        在编译完成后,可能会遇到一些缺少库的提示,尽量安装完成,参考如下

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_dbm                  _tkinter                            
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

可以使用相关的一些指令去安装,例如

sudo apt-get install xxx (或者libxxx-dev)  //xxx 未上面报的缺少的内容

安装:

        

sudo make altinstall

 安装后遇到的问题

   1.error while loading shared libraries: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

问题根因

         系统默认加载/usr/lib,/lib下面库文件,python3.9 默认安装到非此类文件夹,所以查找不到相关的lib

解决方案

        1,cp /usr/local/lib/libpython3.9.so.1.0 /usr/lib64

                ldconfig

        2,cp /usr/local/lib/libpython3.9.so.1.0 /usr/lib

             echo "/usr/lib" > /etc/ld.so.conf.d/python3.9.conf

                ldconfig

重点:以上修改原理都一样,根据个人爱好。我 用的第一个。一定要运行ldconfig,这个很重要。

2. terminal 或者终端打不开

        问题根因:

               使用原生的xterm ,运行命令:gnome-terminal.报错如下:

        

指定默认python版本

由于系统中有多个python 版本,需要指定使用哪个,网上有各种各样的版本,我建议使用正规方式,使用update-alternatives的方式

        1,确认都有系统哪些python版本 

        可以通过ls /usr/bin/python* 等方式来确认

2,使用update-alternatives来修改

*************************:~$  update-alternatives --help
Usage: update-alternatives [<option> ...] <command>Commands:--install <link> <name> <path> <priority>[--slave <link> <name> <path>] ...add a group of alternatives to the system.--remove <name> <path>   remove <path> from the <name> group alternative.--remove-all <name>      remove <name> group from the alternatives system.--auto <name>            switch the master link <name> to automatic mode.--display <name>         display information about the <name> group.--query <name>           machine parseable version of --display <name>.--list <name>            display all targets of the <name> group.--get-selections         list master alternative names and their status.--set-selections         read alternative status from standard input.--config <name>          show alternatives for the <name> group and ask theuser to select which one to use.--set <name> <path>      set <path> as alternative for <name>.--all                    call --config on all alternatives.<link> is the symlink pointing to /etc/alternatives/<name>.(e.g. /usr/bin/pager)
<name> is the master name for this link group.(e.g. pager)
<path> is the location of one of the alternative target files.(e.g. /usr/bin/less)
<priority> is an integer; options with higher numbers have higher priority inautomatic mode.Options:--altdir <directory>     change the alternatives directory(default is /etc/alternatives).--admindir <directory>   change the administrative directory(default is /var/lib/dpkg/alternatives).--instdir <directory>    change the installation directory.--root <directory>       change the filesystem root directory.--log <file>             change the log file.--force                  allow replacing files with alternative links.--skip-auto              skip prompt for alternatives correctly configuredin automatic mode (relevant for --config only)--quiet                  quiet operation, minimal output.--verbose                verbose operation, more output.--debug                  debug output, way more output.--help                   show this help message.--version                show the version.

显示配置

update-alternatives --display python3

 若果没有,就按照规则添加

sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.9 2
sudo update-alternatives --install /usr/bin/python3 python3 /usr//bin/python3.10 1

后面的数字越大,优先级越高

选择默认python 配置

sudo  update-alternatives --config  python3

根据提示,输入需要python版本前面的数字

持续更新中。。。

http://www.lryc.cn/news/538668.html

相关文章:

  • 滑动窗口算法篇:连续子区间与子串问题
  • Python爬虫实战:股票分时数据抓取与存储 (1)
  • 【设计模式】【行为型模式】访问者模式(Visitor)
  • 基于实例详解pytest钩子pytest_generate_tests动态生成测试的全过程
  • Copilot基于企业PPT模板生成演示文稿
  • 2025百度快排技术分析:模拟点击与发包算法的背后原理
  • 七星棋牌全开源修复版源码解析:6端兼容,200种玩法全面支持
  • 解锁原型模式:Java 中的高效对象创建之道
  • DeepSeek从入门到精通:揭秘 AI 提示语设计误区与 AI 幻觉(新手避坑指南)
  • Jenkins同一个项目不同分支指定不同JAVA环境
  • 从入门到精通:Postman 实用指南
  • win32汇编环境,对话框中使用月历控件示例二
  • gsoap实现webservice服务
  • 容联云联络中心AICC:深度整合DeepSeek,业务验证结果公开
  • 腿足机器人之七- 逆运动学
  • 快速点位排查问题的方法
  • 【前端】Vue组件库之Element: 一个现代化的 UI 组件库
  • 一文搞懂Android应用元素查看器(Appium+Appium-inspector)——定位微信布局元素
  • matlab质子磁力仪传感器线圈参数绘图
  • WPF快速创建DeepSeek本地自己的客户端-基础思路版本
  • FreeRTOS第12篇:系统的“绿色通道”——中断管理与临界区
  • SpringBoot+Vue+数据可视化的动漫妆造服务平台(程序+论文+讲解+安装+调试+售后等)
  • CentOS 7超详细安装教程(含镜像)
  • 一种棋牌网游的玩法
  • 9.综合调试|输入不能存在空格|desc存在None|输出权值和ID|函数重名|修改文件名|权值和实际关键词出现次数(C++)
  • 使用SHOW PROCESSLIST和SHOW ENGINE INNODB STATUS排查mysql锁等待问题
  • ElasticSearch映射分词
  • JVM——堆的回收:引用计数发和可达性分析法、五种对象引用
  • PosgreSQL比MySQL更优秀吗?
  • 冒险岛079 V8 整合版源码搭建教程+IDEA启动