Skip to content

Import Error with lxml==5.2.1 #236

@medley56

Description

@medley56

Context

User reported an import exception

bash-3.2$ IMAP_DATA_DIR=~/data IMAP_DATA_ACCESS_URL=[https://api.dev.imap-mission.com/](https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fapi.dev.imap-mission.com%2F&data=05%7C02%7CGavin.Medley%40lasp.colorado.edu%7C70653063081b4142915108de602b8fba%7Cb1ddd7831dbc446b878fa7b03478ea9e%7C1%7C0%7C639053937393044159%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=vpIZV0kIAHqQjyzzalynvc7ZK2zlr3tllHQqTfzqZbQ%3D&reserved=0) IMAP_API_KEY=70bc0c4d2eeea438044a777881464c128689d3627eea31da8b30eeb26541afac imap_cli --instrument hi --data-level l2 --descriptor h90-ena-h-sf-nsp-ram-hae-4deg-1yr --start-date 20260101 --version v999 --dependency imap_hi_l2_test-dependency-json-1yr_20260331_v900.json

Traceback (most recent call last):

  File "/opt/anaconda3/bin/imap_cli", line 5, in <module>

    from imap_processing.cli import main

  File "/Users/dreisen/IMAP/imap_processing/imap_processing/cli.py", line 55, in <module>

    from imap_processing.codice import codice_l1a, codice_l1b, codice_l2

  File "/Users/dreisen/IMAP/imap_processing/imap_processing/codice/codice_l1a.py", line 10, in <module>

    from imap_processing.codice.codice_l1a_de import l1a_direct_event

  File "/Users/dreisen/IMAP/imap_processing/imap_processing/codice/codice_l1a_de.py", line 19, in <module>

    from imap_processing.utils import combine_segmented_packets

  File "/Users/dreisen/IMAP/imap_processing/imap_processing/utils.py", line 10, in <module>

    import space_packet_parser as spp

  File "/opt/anaconda3/lib/python3.12/site-packages/space_packet_parser/__init__.py", line 5, in <module>

    from space_packet_parser.common import SpacePacket

  File "/opt/anaconda3/lib/python3.12/site-packages/space_packet_parser/common.py", line 142, in <module>

    class XmlObject(metaclass=ABCMeta):

  File "/opt/anaconda3/lib/python3.12/site-packages/space_packet_parser/common.py", line 153, in XmlObject

    tree: ElementTree.ElementTree | None,

          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

TypeError: unsupported operand type(s) for |: '_cython_3_0_10.cython_function_or_method' and 'NoneType'

bash-3.2$ pip install --upgrade space_packet_parser

Requirement already satisfied: space_packet_parser in /opt/anaconda3/lib/python3.12/site-packages (6.1.0)

Requirement already satisfied: click>=8.0 in /opt/anaconda3/lib/python3.12/site-packages (from space_packet_parser) (8.1.7)

Requirement already satisfied: lxml>=4.8.0 in /opt/anaconda3/lib/python3.12/site-packages (from space_packet_parser) (5.2.1)

Requirement already satisfied: rich>=13.0 in /opt/anaconda3/lib/python3.12/site-packages (from space_packet_parser) (13.7.1)

Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/anaconda3/lib/python3.12/site-packages (from rich>=13.0->space_packet_parser) (2.2.0)

Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/anaconda3/lib/python3.12/site-packages (from rich>=13.0->space_packet_parser) (2.15.1)

Requirement already satisfied: mdurl~=0.1 in /opt/anaconda3/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=13.0->space_packet_parser) (0.1.0)

Reproducible Example

Install lxml 5.2.1 (might require building from source during install so needs libz-dev, libxslt-dev and libxml2-dev and gcc

apt-get install libz-dev libxml2-dev libxslt-dev gcc
pip install space_packet_parser==6.0.1
pip install lxml==5.2.1
import space_packet_parser as spp

Fix

Revert the pipe-style (|) comparisons with lxml objects to Unions and add # noqa comments so ruff doesn't complain. Test with lxml versions and update the dependency spec if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions