Centos安装Python3.7.6的Crypto,pycryptodome,ibm_db,requests,

发布时间:2024年01月11日

Centos安装Python3.7.6的Crypto,pycryptodome,ibm_db,requests,

Python版本:python3.7.6 对应的各种模块

前言:把python项目放到linux上运行时,提示缺少各种模块,安装命令如下

1、提示:ModuleNotFoundError: No module named 'Crypto'

1.1、报错信息:

Traceback (most recent call last):
? File "casbrun.py", line 12, in <module>
? ? import common
? File "./common/common.py", line 3, in <module>
? ? from Crypto.PublicKey import RSA
ModuleNotFoundError: No module named 'Crypto'

#用到的
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as PKCS1_cipher

1.2、解决办法:

安装:pip install?pycryptodome

或pip3 install?pycryptodome

2、? 提示:File "casbrun.py", line 13, in <module>

2.1、报错信息:

Traceback (most recent call last):
? File "casbrun.py", line 13, in <module>
? ? from aoeweb import AOEWeb

原因:引用其他文件夹的py时,需要先加载文件夹

2.2、解决办法:

import sys
sys.path.append('./server')   #server为文件夹,为服务py
sys.path.append('./common')   #common为文件夹,为工具py
import common
from aoeweb import AOEWeb

3、提示:ModuleNotFoundError: No module named 'ibm_db'

pip3 install ibm-db==3.0.1

4、提示:ModuleNotFoundError: No module named 'requests'

4.1、报错信息:

Traceback (most recent call last):
? File "casbrun.py", line 13, in <module>
? ? from aoeweb import AOEWeb
? File "./server/aoeweb.py", line 6, in <module>
? ? import requests
ModuleNotFoundError: No module named 'requests'

4.2、解决办法:

pip3 install?requests

5、request用到的openssl版本和系统的openssl版本不一致

5.1、报错信息:

Traceback (most recent call last):
? File "casbrun.py", line 13, in <module>
? ? from aoeweb import AOEWeb
? File "./server/aoeweb.py", line 6, in <module>
? ? import requests
? File "/usr/local/lib/python3.7/site-packages/requests/__init__.py", line 43, in <module>
? ? import urllib3
? File "/usr/local/lib/python3.7/site-packages/urllib3/__init__.py", line 42, in <module>
? ? "urllib3 v2.0 only supports OpenSSL 1.1.1+, currently "
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

原因:提示requests用到的openssl版本是openssl1.1.1 ,和当前系统的openssl版本不一致

5.2、解决办法(1、升级openssl 2、编译python,使用最新的openssl)-->未解决

1、先查看openssl版本:openssl version -a

2、centos7升级openssl到openssl1.1.1

参考:Centos7升级openssl到openssl1.1.1

Centos7升级openssl到openssl1.1.1-CSDN博客

#删除软链接和重新建立软链接

rm /usr/bin/openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

echo "/usr/local/openssl/lib/" >> /etc/ld.so.conf
ldconfig -v

#加载环境变量

export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH

$source /etc/profile

$echo $LD_LIBRARY_PATH

3、升级python3的openssl

如果你使用的是源代码包,可以通过在运行./configure命令时传递–with-openssl参数,并指定新版本的OpenSSL库所在的路径来配置Python的编译选项。

$cd?cd Python-3.7.6

#编译

$./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl

看到:checking for openssl/ssl.h in /usr/local/openssl... yes
? ? ? ? ? ?checking whether compiling and linking against OpenSSL works... yes

$make clean

$make & make install

#备注,如果有问题就make之后再make install

#加入python3的软链接

rm /usr/bin/python3

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

参考:https://codeleading.com/article/19232024257/

参考:https://blog.csdn.net/inthat/article/details/131365519

https://blog.csdn.net/weixin_63133658/article/details/134380096

4、检查 Python 的?ssl?模块版本:

python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"

文章来源:https://blog.csdn.net/fen_fen/article/details/135502232
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。