Centos7,Python3.7.6安装模块Crypto,pycryptodome,ibm_db,requests,requests_pkcs12

Centos7,Python3.7.6安装模块Crypto,pycryptodome,ibm_db,requests,requests_pkcs12

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、ModuleNotFoundError: No module named 'pandas'

Traceback (most recent call last):
  File "DB2OPE.py", line 2, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

5.2、解决办法:

$pip3 install pandas==0.23.4

6、ModuleNotFoundError: No module named 'requests_pkcs12'

6.1、报错信息:

  File "casbrun.py", line 13, in <module>
    from aoeweb import AOEWeb
  File "./server/aoeweb.py", line 8, in <module>
    from getfile import Getfile
  File "./common/getfile.py", line 8, in <module>
    import requests_pkcs12
ModuleNotFoundError: No module named 'requests_pkcs12'

6.2、解决办法:

pip3 install requests_pkcs12

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

7.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版本不一致

7.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

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 /usr/bin/pip3

其中pip3不可用时解决

[root@loaclhost bin]# pip3
-bash: /usr/local/bin/pip3: No such file or directory
[root@loaclhost bin]# cp /usr/local/python3/bin/pip3 /usr/local/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)"

8、linux查看python的site-packages路径

有时候我们在liunx上想修改查看python的包路径可以试试以下命令

from distutils.sysconfig import get_python_lib

print(get_python_lib())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁宁可可

您的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值