AttributeError: module 'icu' has no attribute 'Locale'

Bug #2018666 reported by Benjamin Drung
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
natsort (Ubuntu)
New
Undecided
Unassigned

Bug Description

I stumbled over this crash during import while I was working on the tzdata package update. How to reproduce: Install natsort, but do not install the icu Python module. Create an empty directory called `icu` and then try to import natsort:

```
$ sudo apt install python3-natsort
$ sudo apt remove python3-icu
$ mkdir icu
$ python3 -c "import natsort"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/natsort/__init__.py", line 3, in <module>
    from natsort.natsort import (
  File "/usr/lib/python3/dist-packages/natsort/natsort.py", line 846, in <module>
    os_sort_key = os_sort_keygen()
                  ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/natsort/natsort.py", line 814, in os_sort_keygen
    loc = natsort.compat.locale.get_icu_locale()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/natsort/compat/locale.py", line 42, in get_icu_locale
    return cast(str, icu.Locale(".".join(getlocale())))
                     ^^^^^^^^^^
AttributeError: module 'icu' has no attribute 'Locale'
```

ProblemType: Bug
DistroRelease: Ubuntu 23.04
Package: python3-natsort 8.0.2-2
ProcVersionSignature: Ubuntu 6.2.0-20.20-generic 6.2.6
Uname: Linux 6.2.0-20-generic x86_64
ApportVersion: 2.26.1-0ubuntu2
Architecture: amd64
CasperMD5CheckResult: pass
CurrentDesktop: ubuntu:GNOME
Date: Sun May 7 00:37:52 2023
Dependencies:

InstallationDate: Installed on 2022-03-09 (423 days ago)
InstallationMedia: Ubuntu 21.10 "Impish Indri" - Release amd64 (20211012)
PackageArchitecture: all
SourcePackage: natsort
UpgradeStatus: Upgraded to lunar on 2023-04-25 (11 days ago)

Revision history for this message
Benjamin Drung (bdrung) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.