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为文件夹,为工具pyimport 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/opensslecho "/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())