YUM reports No module named yum processing

1. Problem description

insert image description here

During the deployment of a GreenPlum cluster, the on-site personnel reported that the yum command could not be used, and the execution error: No module named yum, as shown below:

insert image description here
Related information: YUM

2. Problem analysis and treatment

2.1 The essence of YUM

The yum command is essentially a module belonging to python. When you open /usr/bin/yum, you will find the first line of command #!/usr/bin/python, that is, its executor/parser is python, and the yum module is imported. And python has a very important lib library file, which is in the **/usr/lib64** directory by default, the full name is libpython2.7.so.1.0 (corresponding to python2.7), and python will first call this lib every time it is executed Libraries, python and lib libraries have a one-to-one correspondence. Normally, yum is used through the python that comes with the system, that is, it needs to call the lib library of python that comes with the OS. Yum calls python using an absolute path. It strongly relies on this python. When the yum command cannot find the original it calls When the library file is installed, the above error message will be reported, so what we have to do is to let yum continue to call the original python and the original python lib library.
insert image description here

After the on-site GPDB is deployed, it brings python versions 2.7 and 3.4 and the corresponding library files. Once the global environment variables are configured, the path of the python library or execution file must be modified, causing the yum call to fail and report an error. You can also check the environment variable PYYHONHOME on site;
insert image description here
insert image description here
for the above problems, comment the environment variable configuration, log out and reopen it

2.2, upgrade python or use a higher version to pay attention

Unfortunately, no relevant information was found. Yum has a place to configure the path of the lib library file. It still looks for the lib library file in the default path; then, when we upgrade python and the lib library file is updated, we need to configure additional for yum. The lib library file path or add the old library file to the new library file, the configuration method is as follows:

1) Newly configure the lib library path, which is realized by configuring the LD_LIBRARY_PATH global environment variable

LD_LIBRARY_PATH is used to specify paths other than the default path (/lib and /usr/lib) when searching for shared libraries (dynamic link libraries). We can set the new library file directory to LD_LIBRARY_PATH to let the system find it;

vim /etc/bashrc  #或/etc/profile
export LD_LIBRARY_PATH=/usr/local/python2.7.15/lib:$LD_LIBRARY_PATH
export PATH=/usr/local/python2.7.15/bin:$PATH

#或
cp /usr/lib64/libpython2.7.so.1.0.bak /usr/local/python2.7.5/lib/libpython2.7.so.1.0
mv /usr/bin/yum /usr/bin/yum-exec #重命名

#新建/usr/bin/yum文件,内容如下: 
#$@和$*都表示命令行所有的参数(不包含$0),但是$*将命令行所有的参数看成一个整体,而$@则区分各个参数
#!/bin/bash
export LD_LIBRARY_PATH=/usr/local/python2.7.5/lib/
/usr/bin/yum-exec $*

#添加可执行权限:
chmod +x /usr/bin/yum
#检查yum是否已经可用
yum list installed
yum --version

Knowledge review:

1. $#: Indicates the number of parameters passed in by executing the script

2. $*: Indicates the list of parameters passed in by executing the script (excluding $0)

3. $$: Indicates the id of the process; the PID of the Shell itself (ProcessID, ie The current process ID number of the script running)

4. $!: The PID of the background process that the shell last runs (the process ID number of the last process running in the background)

5. $@: means to get all the parameters passed in by executing the script

6. $0 : indicates the name of the executed script

7, $1: indicates the first parameter

9, $?: indicates the status of script execution, 0 indicates normal, others indicate error

2) Replace the file (recommended)

# 备份原来的lib库文件
mv /usr/lib64/libpython2.7.so.1.0 /usr/lib64/libpython2.7.so.1.0.bak
# 将python的bin目录加入到PATH中
echo 'export PATH=/usr/local/python2.7.15/bin:$PATH' >> /etc/profile
# 将新的lib库文件拷贝至/usr/lib64下
cp /usr/local/python2.7.15/lib/libpython2.7.so.1.0 /usr/lib64/
source /etc/profile

3. Appendix

3.1、 LIBRARY_PATH 和 LD_LIBRARY_PATH

LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that need to be linked to your program. LD_LIBRARY_PATH is used by your program to search for directories

containing the libraries after It has been successfully compiled and linked. Specify a path other than the system default path when searching for a dynamic link library during program loading and running

Guess you like

Origin blog.csdn.net/ximenjianxue/article/details/131108642
yum