packit / rpm-shim

Python RPM shim module for use in virtualenvs
MIT License
2 stars 4 forks source link

Importing rpm fails on openSUSE Leap from a virtualenv #9

Closed dcermak closed 2 weeks ago

dcermak commented 1 month ago

What happened? What is the problem?

The rpm module fails to initialize rpm in a virtualenvironment on openSUSE Leap with python 3.11. To reproduce:

$ podman run --pull=always --rm -it registry.opensuse.org/opensuse/leap:15.6
# zypper -n in python311 python311-pip python311-rpm
# cd home/
# python3.11 -m venv .env3
# source .env3/bin/activate
(.env3) # pip install rpm
Collecting rpm
  Downloading rpm-0.1.0-py3-none-any.whl.metadata (2.5 kB)
Downloading rpm-0.1.0-py3-none-any.whl (4.0 kB)
Installing collected packages: rpm
Successfully installed rpm-0.1.0

[notice] A new release of pip is available: 24.0 -> 24.1.1
[notice] To update, run: pip install --upgrade pip
(.env3) # python
Python 3.11.9 (main, Apr 15 2024, 10:36:26) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpm
Traceback (most recent call last):
  File "/home/.env3/lib64/python3.11/site-packages/rpm/__init__.py", line 102, in <module>
    _shim_module_initializing_
NameError: name '_shim_module_initializing_' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.env3/lib64/python3.11/site-packages/rpm/__init__.py", line 105, in <module>
    initialize()
  File "/home/.env3/lib64/python3.11/site-packages/rpm/__init__.py", line 94, in initialize
    raise ImportError(
ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.
>>> 

What did you expect to happen?

The import to succeed

Example URL(s)

No response

Steps to reproduce

No response

Workaround

Participation

ricardobranco777 commented 1 month ago

Also hit by this issue but it seems to affect only the Leap 15.6 image and not a bare-metal installation.

ktdreyer commented 2 weeks ago

Looks similar to the problem I found on Red Hat's ubi9 with the python311 stack there: https://github.com/packit/rpm-shim/issues/10

nforro commented 2 weeks ago

Looks similar to the problem I found on Red Hat's ubi9 with the python311 stack there: #10

Yes, the fix for https://github.com/packit/rpm-shim/issues/10 will fix also this issue. Although the traceback would look similar even if it was a completely different issue :slightly_smiling_face:

Also hit by this issue but it seems to affect only the Leap 15.6 image and not a bare-metal installation.

It depends on whether /usr/bin/python3 is present or not, in the image there is no Python and you install python311 which installs python311-base which provides /usr/bin/python3.11.