当前位置: 首页 > 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 the
                           user 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 in
  automatic 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 configured
                           in 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版本前面的数字

持续更新中。。。

相关文章:

  • AI Agent 技术在网络中有什么应用
  • 正顺基碱基
  • 【深度学习】环境和分布偏移
  • TCP/UDP协议与OSI七层模型的关系解析| HTTPS与HTTP安全性深度思考》
  • 【Mysql索引在什么情况下会失效?】
  • Kubernetes: Kustomize 进阶, 使用 Patch 精准操控 ConfigMap 多行文本,实现配置参数化
  • 笔记9——循环语句:for语句、while语句
  • PageHelper分页异常深度解析与解决方案
  • Maven 中的 Artifact 与 GroupId:定义与使用
  • 【愚公系列】《Python网络爬虫从入门到精通》019-使用 BeautifulSoup 的CSS选择器
  • deepseek本地调用
  • vscode的一些实用操作
  • CMake 编译工具
  • python基础语法
  • Spring Boot 与 Java 决策树:构建智能分类系统
  • 把程序加入开机自启动
  • 数据结构——单向循环链表、双链表、双向循环链表
  • Ubuntu 下 MySQL 安装与配置全攻略:从入门到精通
  • Zotero PDF Translate插件配置百度翻译api
  • 算法——前缀和
  • 准80后湖北省财政厅副厅长徐晶华已调任襄阳市副市长
  • 被算法重塑的世界,人与技术如何和谐共处
  • 企业取消“大小周”引热议,半月谈:不能将显性加班变为隐性加班
  • 日韩 “打头阵”与美国贸易谈判,汽车、半导体产业忧虑重重
  • 新任海南琼海市委副书记陈明已主持市政府党组全面工作
  • 因高颜值走红的女通缉犯出狱后当主播自称“改邪归正”,账号已被封