首页 > 系统相关 >python3 番外篇之Linux环境安装问题

python3 番外篇之Linux环境安装问题

时间:2023-08-02 17:48:56浏览次数:36  
标签:None openssl usr install Linux requests 番外篇 python3 connect

问题一、Linux主机openSSL版本较老

[root@zabbix-server alertscripts]# python3 feishu.py
Traceback (most recent call last):
  File "feishu.py", line 3, in <module>
    import requests
  File "/usr/local/python3.8/lib/python3.8/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/usr/local/python3.8/lib/python3.8/site-packages/urllib3/__init__.py", line 41, in <module>
    raise ImportError(
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips  26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168

解决办法:
  1、升级系统openssl
  2、重新编译安装python3

openssl升级脚本:

openssl下载官网:https://www.openssl.org/source/

#!/bin/bash
# 没有编译环境需要安装编译环境: yum groupinstall "Development Tools"
sslpkg=openssl-1.1.1v.tar.gz

if [ ! -f /usr/local/openssl ];then
   mkdir -pv /usr/local/openssl
fi

function downloadurl(){
    wget https://www.openssl.org/source/$sslpkg --no-check-certificate
}

function install(){
    tar xf $sslpkg
    ssldir=`echo $sslpkg | cut -f 1,2,3 -d"."`

    cd $ssldir
    ./config --prefix=/usr/local/openssl
    make
    make install
}

function changecfg(){
    # 备份原来的配置
    mv /usr/bin/openssl /usr/bin/openssl.bak
    mv /usr/include/openssl /usr/include/openssl.bak

    # 添加新的openssl软连接
    ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
    ln -s /usr/local/openssl/include/openssl /usr/include/openssl

    # 将新的库文件地址写入记录so库的配置文件
    echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

    # 重载使其生效
    ldconfig -v
}

downloadurl
install

if [ $? -eq 0 ];then
changecfg
openssl version -a
fi

需要重新编译python3

# 如果之前编译过,需要执行make clean清除一下之前编译的包否则编译完成后会不生效。
./configure --prefix=/usr/local/python3.8 --with-openssl=/root/openssl-1.1.1v --with-openssl-rpath=auto
make
make install

问题二、SSLError

[root@zabbix-server write-bash]# pip3 install requests
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting requests
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/requests/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/requests/
  WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/requests/
  WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/requests/
  WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/requests/
  Could not fetch URL https://pypi.org/simple/requests/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/requests/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
  ERROR: Could not find a version that satisfies the requirement requests (from versions: none)
ERROR: No matching distribution found for requests
WARNING: You are using pip version 19.2.3, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

解决办法:

vim /root/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host = mirrors.aliyun.com

然后再执行 "python3 -m pip install --upgrade pip" 把pip升级一下就ok了。

问题三、ModuleNotFoundError: No module named '_ctypes'

解决办法:
  CentOS7: yum install libffi-devel
  Ubuntu: apt-get install libffi-dev
  再次重新编译安装python3

标签:None,openssl,usr,install,Linux,requests,番外篇,python3,connect
From: https://www.cnblogs.com/zhangzhide/p/17601323.html

相关文章

  • Linux系统中查看某个命令的路径
    https://blog.csdn.net/weixin_44799217/article/details/128783337 Linux下有两个命令可以查看命令或者文件所在的位置。1.whichwhich用来查看当前要执行的命令所在的路径。which命令的原理:在PATH变量指定的路径中,搜索某个系统命令的位置,并且返回第一个搜索结果。......
  • Linux基础知识总结
    Linux快捷键:ctrl+l清空屏幕Linux文件系统FHS3.0(FilesystemHierarchyStandard)/etc配置文件bin必要命令usr二级目录home家目录var动态数据VFS虚拟文件系统内核层抽象出通用的文件系统接口支持文件、网络、特殊文件系统抽象对象:超级快:文件系......
  • Linux和windows区别
    Linux和windows区别开源VS闭源:Linux是开源的系统,其内核和大部分的软件的代码都是公开的,任何人都可以进行修改、查看。而windows操作系统则是闭源的商业操作系统,其源代码是不公开的,只有微软公司才能够进行修改等操作。发行模式:Linux以发行版的形式进行发布,如Ubuntu、CentOS等,每个发......
  • Linux su命令:su命令语法、su root与su - root区别、su与sudo区别、su -c 参数的使用理
    https://www.cnblogs.com/goloving/p/15150206.html Linuxsu(英文全拼:switchuser)命令用于变更为其他使用者的身份,除root外,需要键入该使用者的密码。使用权限:所有使用者。一、语法su[-fmp][-ccommand][-sshell][--help][--version][-][USER[ARG]]1、参数说......
  • Linux1
    Linux的目录结构一:Linux的目录结构Linux没有盘符的概念,只有一个顶级目录(根目录/),所有文件都在它下面   二:Linux路径的描述方式在Linux系统中,路径之间的层级关系,用:/来表示在Windows系统中,路径之间的层级关系,用:\来表示 在Windows系统中描述hello.......
  • paddleocr Linux安装lanms-neo报错
     检查一般来说是g++环境问题添加源根据不同的的系统查找编辑/etc/apt/sources.list debhttp://archive.ubuntu.com/ubuntubionicmainuniverse 更新gcc和g++sudoapt-getupdatesudoapt-getinstallgcc-6sudoaptinstallg++-6sudoupdate-alternatives--......
  • 在Windows实例上无法连接搭建在Linux实例上的VSFTP站点,如何处理?
    本文介绍在Windows实例上,无法连接搭建在Linux实例上VSFTP(VerySecureFTP)服务问题的问题原因和解决方案。问题描述在Windows操作系统资源管理器的文件夹路径中,通过输入ftp://FTP站点所在的ECS实例公网IP地址:21方式,访问搭建在Linux实例上的VSFTP服务,出现无法连接或无法登录FTP......
  • python3 压缩图片到合理范围
    importosfromPILimportImagefromPILimportImageFileimportimghdrdefcompress_image(outfile,mb=200,quality=85,k=0.9):#修改mb大小,就是想要设定的压缩后的大小。"""不改变图片尺寸压缩到指定大小:paramoutfile:压缩文件保存地址:parammb:压缩目标,KB:pa......
  • linux 中umask的作用(还可以)
    https://blog.csdn.net/sinat_42724379/article/details/124752536  ____________________________________________________________________________________________________________________ 我们知道在linux服务器中文件最大权限为666,而目录最大权限为777但是一般我......
  • RHEL/RedHat:Linux虚拟机安装minikube
    学习自容器与云|如何在RHEL8上安装MiniKube(主要参考这个)第五篇:minikube安装使用这个教程装了两步之后发现是Centos,而我的是rhel,遂放弃系统相关Linux服务器:Linuxrhel1.myguest.virtualbox.org3.10.0-1160.el7.x86_64#1SMPTueAug1814:50:17EDT2020x86_64x86_......