Python高版本降低低版本导致python导包异常的问题

Python高版本降低低版本导致python导包异常的问题

问题描述

使用的python版本为3.12和3.10,需要的版本为python3.9.20,将python的版本降低到3.9.20之后,出现zookeeper等的包导入补进去,但是pip list查看已经存在kazoo的包。

报错日志如下:

2025-04-22 16:01:00,717 17930 INFO "log.py:202" logger listener process started with PID 17931.
2025-04-22 16:01:00,728 17930 DEBUG "__init__.py:123" Failed to import center.dcs.zookeeper
2025-04-22 16:01:00,729 17930 ERROR "center.py:476" Can not find suitable configuration of distributed configuration store
Available implementations: Etcd2, Etcd3, Zookeeper
Traceback (most recent call last):
  File "/opt/soft/fbase-dg/venv-fbase-dg-0.1.0/lib/python3.9/site-packages/center/daemon/center.py", line 463, in run
    self.dcs = get_dcs(self.config)
  File "/opt/soft/fbase-dg/venv-fbase-dg-0.1.0/lib/python3.9/site-packages/center/dcs/__init__.py", line 154, in get_dcs
    raise DCSException(
center.exception.DCSException: Can not find suitable configuration of distributed configuration store
Available implementations: Etcd2, Etcd3, Zookeeper
2025-04-22 16:01:00,731 17930 INFO "center.py:478" Center main process shutdown
2025-04-22 16:03:45,515 18084 INFO "log.py:202" logger listener process started with PID 18085.
2025-04-22 16:03:45,526 18084 DEBUG "__init__.py:123" Failed to import center.dcs.zookeeper

python版本:

(venv-fbase-dg-0.1.0) [fbase@dg-3 log]$ python -V
Python 3.9.20

产生原因

对于低版本造的轮子urllib3-1.26.6-py2.py3-none-any.whl有些在高版本python用不了才降低版本,之后排除问题,确实是因为3.10以上的python版本需要升级openssl才能使用,因此这里给出的解决版本是降低openssl的版本和python版本,还可以使用原来的高版本,但是不能使用脚本一键安装了。

解决方案

这里采用高版本python安装。

  1. 将python版本替换为3.12版本。

    cp /usr/local/python/3.12/lib/libpython3.so /usr/lib64/
    cp /usr/local/python/3.12/lib/libpython3.12.so.1.0 /usr/lib64/
    
    cd /usr/lib64
    rm /usr/lib64/libpython3.12.so
    ln -s libpython3.12.so.1.0 /usr/lib64/libpython3.12.so
    
    rm /usr/bin/python3
    rm /usr/bin/pip3
    
    ln -s /usr/local/python/3.12/bin/python3.12 /usr/bin/python3
    ln -s /usr/local/python/3.12/bin/pip3.12 /usr/bin/pip3
    
  2. 重新安装python虚拟环境。

    cd /opt/soft/fbase-dg
    rm -rf venv-fbase-dg-0.1.0/
    
    # 退出安装用户(fbase)重新登录
    sh install.sh
    
    # 会报错
    # Looking in links: /opt/soft/fbase-dg/package
    # ERROR: Could not find a version that satisfies the requirement cffi<=1.17.1 (from versions: none)
    # ERROR: No matching distribution found for cffi<=1.17.1
    
  3. 激活虚拟环境,安装依赖文件中的依赖包,以及fbase-dg、patroni等依赖。

    source venv-fbase-dg-0.1.0/bin/activate
    pip3 install -r package/requirements.txt
    cd package/
    pip3 install fbase_dg-0.2.0-py3-none-any.whl
    pip3 install patroni-4.0.4-py3-none-any.whl
    

问题成功解决。

(venv-fbase-dg-0.1.0) [fbase@dg-4 package]$ dgcenter -c /usr/local/center/center.ini dry-run
logger listener process started with PID 22923. 
Dry-Run Result: True
posted @ 2025-04-30 16:06  零の守墓人  阅读(54)  评论(0)    收藏  举报