问题背景:
输入yum命令:
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It’s possible that the above module doesn’t match the
current version of Python, which is:
2.7.12 (default, Jun 21 2021, 15:39:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
此问题发生在安装greenplum后,源码编译安装
本机yum为3.4 (yum --version) 与python2.7匹配
命令行输入:
whereis python:发现有python2.7和3.6两个版本
系统所用yum和python版本可以匹配
命令行输入python2.7:import yum 报错找不到yum库
假设问题原因:
参考下面两个,大体是因为安装软件后,python的路径变化,软件的python可能和系统自带的python不一样,比如支持的库不太一样
https://superuser.com/questions/1608908/no-module-named-yum-with-python2-7-in-centos-7
https://access.redhat.com/solutions/21199
解决:
PYTHONHOME和PYTHONPATH两个环境变量路径设置错误
现在的PYTHONPATH中没有yum库文件,果然greenplum自己设置的pythonpath不行
查找正确的环境变量:
方法一:
查看python库路径有没有yum文件:
find / -name “site-packages”
/usr/lib/python2.7/site-packages
/usr/lib/python3.6/site-packages
/usr/lib64/python3.6/site-packages
/usr/lib64/python2.7/site-packages
/usr/local/lib/python3.6/site-packages
/usr/local/lib64/python3.6/site-packages
/usr/local/greenplum/greenplum-db-6.16.3/ext/python/lib/python2.7/site-packages
发现/usr/lib/python2.7/site-packages有,则export PYTHONPATH=“/usr/lib/python2.7/site-packages/:/usr/lib64/python2.7/site-packages/”
PYTHONHOME先不动
到这有的机器可能就行了,把对应的环境变量设置在.bashrc中
方法二:
找到默认的环境变量值再设置
方法一不行的话,则命令行输入:
unset PYTHONHOME
unset PYTHONPATH
python2.7:
import sys
print(sys.prefix)
print(sys.exec_prefix)
print(sys.path)
出来设置PYTHONHOME:Consider setting $PYTHONHOME to [:<exec_prefix>]
export PYTHONHOME=“/usr:/usr”
PYTHONPATH参考sys.path设置(注意到site-packages)
export PYTHONPATH=“/usr/lib/python2.7/site-packages/:/usr/lib64/python2.7/site-packages/”
设置完注意设置环境变量,source .bashrc source .bash_profile试下有没问题;
有些环境变量设置在greenplum自己的用户下,root用户下不用设置,本人测试可以启动成功(上面网站说安装软件时最好不要编译,要yum安装,可能是编译会导致环境变量改变吧)
网上很多说把python卸载重装,可能是python重装后环境变量自动变回来了,换汤不换药,看问题原因吧