Bug 1626408

Summary: sealert: AttributeError: module 'pkg_resources' has no attribute 'get_distribution'
Product: Red Hat Enterprise Linux 8 Reporter: Martin Hoyer <mhoyer>
Component: python-pipAssignee: Victor Stinner <vstinner>
Status: CLOSED CURRENTRELEASE QA Contact: Maryna Nalbandian <mnalband>
Severity: unspecified Docs Contact: Lenka Špačková <lkuprova>
Priority: unspecified    
Version: 8.0CC: cstratak, igkioka, jkejda, jwboyer, lvrabec, mhroncok, mmalik, plautrba, pviktori, torsava, vmojzis, vstinner
Target Milestone: rc   
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-pip-9.0.3-11.el8 Doc Type: Bug Fix
Doc Text:
When updating a Python package, pip conflicts with dnf: it removes files installed by dnf in /usr. It causes applications run by "python3 -I" to fail to import the module installed by dnf. pip has been fixed to only install new files in /usr/local, but leave files installed by rpm in /usr/local unchanged. For example, it is now possible to have and old version of setuptools installed by dnf in /usr, and a newer version installed by pip in /usr/local.
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-06-14 01:53:01 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1550368    
Bug Blocks: 1623566, 1650327    

Description Martin Hoyer 2018-09-07 09:02:17 UTC
Description of problem:
Without python2, sealert cmds are not working.

# sealert --help
Traceback (most recent call last):
  File "/usr/bin/sealert", line 56, in <module>
    from setroubleshoot.util import get_identity, load_plugins, log_init, log_debug
  File "/usr/lib/python3.6/site-packages/setroubleshoot/util.py", line 348, in <module>
    from sepolicy import get_all_file_types
  File "/usr/lib/python3.6/site-packages/sepolicy/__init__.py", line 9, in <module>
    import setools
  File "/usr/lib64/python3.6/site-packages/setools/__init__.py", line 24, in <module>
    __version__ = pkg_resources.get_distribution("setools").version
AttributeError: module 'pkg_resources' has no attribute 'get_distribution'


Version-Release number of selected component (if applicable):
setroubleshoot-server-3.3.18-1.el8.x86_64
setroubleshoot-plugins-3.3.9-3.el8.noarch
python36-3.6-5.el8+1588+796e359f.x86_64

How reproducible:
100%

Steps to Reproduce:
1.nstall RHEL-8
2.try to run sealert cmd 

Actual results:
AttributeError

Expected results:
no errors

Comment 1 Milos Malik 2018-09-07 11:06:46 UTC
I tried to add / remove various SELinux related packages on my RHEL-8.0 VM, but sealert --help still works. Could you provide NVRs of SELinux related packages?

# rpm -qa libsepol\* libsemanage\* libselinux\* setroubleshoot\* 
policycoreutils\* selinux-policy\* setools\*

Hopefully, the NVRs help us to find the cause. Thanks!

Comment 2 Petr Lautrbach 2018-09-07 15:07:42 UTC
Do you use pip? Please see https://bugzilla.redhat.com/show_bug.cgi?id=1550368#c21 and later

Comment 3 Martin Hoyer 2018-09-07 15:09:39 UTC
(In reply to Petr Lautrbach from comment #2)
> Do you use pip? Please see
> https://bugzilla.redhat.com/show_bug.cgi?id=1550368#c21 and later

Yes, that's it.

Comment 4 Miro Hrončok 2018-09-21 21:02:28 UTC
Fedora has a fix of the primary cause in https://src.fedoraproject.org/rpms/python-pip/pull-request/16

I leave it to the RHEL experts to decide if and how to fix this in RHEL.

This misbehavior has a potential of destroying systems (rendering dnf/yum unusable), so I'd suggest to take it and fix this before RC.

Comment 5 Miro Hrončok 2018-09-21 21:03:52 UTC
https://src.fedoraproject.org/rpms/python-pip/pull-request/10 has a previous (untested) version fo the patch applicable to pip 9.

Comment 6 Petr Viktorin (pviktori) 2018-09-24 14:18:43 UTC
Problem summary: Upgrading a package to the latest *upstream* release using can remove the RPM-installed version, making it unusable with the rest of the system.

It can be reproduced with:

    $ sudo python3 -m pip install --upgrade setuptools
    $ python3 -Es -c 'import pkg_resources; print(pkg_resources.get_distribution("setools").version)'


Expected: a version number, e.g.
4.1.1

Actual result:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'pkg_resources' has no attribute 'get_distribution'

Comment 7 Miro Hrončok 2018-09-24 14:27:25 UTC
I guess:

   s/using can/using sudo pip can/

Comment 10 Victor Stinner 2018-11-16 16:41:05 UTC
Note: The fix doesn't prevent pip to remove files from /usr:

# dnf install python3-pillow
# ls /usr/lib64/python3.6/site-packages/PIL/version.py 
/usr/lib64/python3.6/site-packages/PIL/version.py

# python3 -m pip uninstall Pillow
Uninstalling Pillow-5.1.1:
  /usr/lib64/python3.6/site-packages/PIL
  /usr/lib64/python3.6/site-packages/Pillow-5.1.1-py3.6.egg-info
Proceed (y/n)? y
  Successfully uninstalled Pillow-5.1.1
You are using pip version 9.0.3, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# ls /usr/lib64/python3.6/site-packages/PIL/version.py 
ls: cannot access '/usr/lib64/python3.6/site-packages/PIL/version.py': No such file or directory

Comment 11 Tomas Orsava 2018-11-16 21:04:52 UTC
I've did some testing as well, didn't notice any problems. It works fine with venv as well.

The uninstallation is a known issue, we could potentially add a warning for that in a later release.

Comment 12 Victor Stinner 2018-11-19 14:20:03 UTC
python-pip-9.0.3-11.el8 is now ready for testing. See my Comment 9 for possible manual validation of the fix.

Comment 22 RHEL Program Management 2019-06-14 01:53:01 UTC
800AutoClose

The change described in this bug report should be resolved in the RHEL 8.0 release.  It has been closed with a resolution of CURRENTRELEASE.

If the solution does not work for you, open a new bug report.

Comment 23 Tomas Orsava 2019-08-26 15:58:01 UTC
*** Bug 1650327 has been marked as a duplicate of this bug. ***