How to completely reinstall python (WITHOUT yum) o

2019-08-20 05:38发布

A series of unfortunate events (in dev, thank goodness) basically has ruined my python2.7 environment. The executable in /usr/bin got clobbered and some rpms ran amok. So I no longer have a viable import yum environment. I actually spun up another EC2 instance and copied off the python exec in hopes that the lib paths would be the same but sadly I got this (running with -v):

( various imports then )
import gpg.core # precompiled from /usr/lib64/python2.7/site-packages/gpg/core.pyc
# /usr/lib64/python2.7/site-packages/gpg/gpgme.pyc matches 
/usr/lib64/python2.7/site-packages/gpg/gpgme.py
import gpg.gpgme # precompiled from /usr/lib64/python2.7/site-packages/gpg/gpgme.pyc
dlopen("/usr/lib64/python2.7/site-packages/gpg/_gpgme.so", 2);
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/gpg/__init__.py", line 101, in <module>
  from . import core
File "/usr/lib64/python2.7/site-packages/gpg/core.py", line 34, in <module>
  from . import gpgme
File "/usr/lib64/python2.7/site-packages/gpg/gpgme.py", line 17, in <module>
_gpgme = swig_import_helper()
File "/usr/lib64/python2.7/site-packages/gpg/gpgme.py", line 16, in swig_import_helper
return importlib.import_module('_gpgme')
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named _gpgme

This is sort of disturbing because of course _gpgme.so is in the same dir as gpgme.py and ldd on _gpgme.so looks OK:

-bash-4.2$ ldd /usr/lib64/python2.7/site-packages/gpg/_gpgme.so
linux-vdso.so.1 =>  (0x00007ffe2cf6d000)
libpython2.7.so.1.0 => /usr/lib64/libpython2.7.so.1.0 (0x00007ff166d5d000)
libgpgme.so.11 => /usr/lib64/libgpgme.so.11 (0x00007ff166b27000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff16690b000)
libc.so.6 => /lib64/libc.so.6 (0x00007ff166547000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007ff166343000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007ff166140000)
libm.so.6 => /lib64/libm.so.6 (0x00007ff165e3e000)
libassuan.so.0 => /usr/lib64/libassuan.so.0 (0x00007ff165c2e000)
libgpg-error.so.0 => /lib64/libgpg-error.so.0 (0x00007ff165a2a000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff1673e7000)

So the question is: how does one force remove python from an AWS Linux image (Linux version 4.9.75-25.55.amzn1.x86_64 (mockbuild@gobi-build-64013) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Fri Jan 5 23:50:27 UTC 2018) and reinstall it WITHOUT the benefit of yum, and then install the necessary yum bits such that /usr/bin/yum (which pretty much just import yum) works?

I know this question is a partial dupe but I have searched stackoverflow and everything seems to lead back to installing python with yum (which I can't) or installing modules with pip (which keeps going to installing pip with yum!) or very broadly saying rpm --erase vagueness followed by rpm -i vagueness.

I did manually rebuild a python exec from source and that runs, but of course it does not come with yum and I cannot seem to find anything in pip search (I got pip running again) that would produce the yum module I seek. You'd think pip install yum would be right there but no. Maybe I missed something...?

I have to believe that there is perhaps a slow but stable way to do this. Knocking out the /usr/bin/python2.7 exec shouldn't create a situation where I seem to have a chicken-and-egg problem...

1条回答
The star\"
2楼-- · 2019-08-20 06:11

Before you follow these steps, download the python-package-version.rpm file to a local directory on the same machine. See step-0 below to get the exact version.

0. Get the python package name
$ rpm -q python

1. Remove python forcefully
$ rpm -e --nodeps <python-package-name>

2. Install the rpm from local dir.
$ rpm -ivvh python-some-version.rpm

3. Retry your yum command
$ yum install <some package>

If (3) fails, you can reinstall yum using rpm, same way that you reinstall python.

From OP's comment, it seems python was never installed on the system, otherwise the dependencies would have been on the system. If on step-2, it asks for dependencies, then one has to download them manually to the same local dir and then invoke.

$ rpm -ivh *.rpm  

or do a dry-run first

$ rpm -ivh --test *.rpm
查看更多
登录 后发表回答