Skip to content

FileNotFoundError: cfunits requires UNIDATA UDUNITS-2. Can't find the 'udunits2' library. on M2 Macbook Pro #53

@wknoben

Description

@wknoben

I'm having some trouble getting cfunits to work on my M2 Macbook Pro. Installing cfunits 3.3.6 reports no errors, but trying to import the package returns a library not found error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/[snip]/lib/python3.11/site-packages/cfunits/__init__.py", line 47, in <module>
    from .units import Units  # noqa: F401
    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/[snip]/lib/python3.11/site-packages/cfunits/units.py", line 43, in <module>
    raise FileNotFoundError(
FileNotFoundError: cfunits requires UNIDATA UDUNITS-2. Can't find the 'udunits2' library.

udunits is present on the system:

brew info udunits
==> udunits: stable 2.2.28 (bottled), HEAD
Unidata unit conversion library
https://www.unidata.ucar.edu/software/udunits/
/opt/homebrew/Cellar/udunits/2.2.28 (29 files, 659.5KB) *
  Poured from bottle using the formulae.brew.sh API on 2024-01-19 at 15:24:29
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/u/udunits.rb
==> Dependencies
Build: texinfo ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 105 (30 days), 477 (90 days), 1,702 (365 days)
install-on-request: 67 (30 days), 293 (90 days), 957 (365 days)
build-error: 0 (30 days)

I (sequentially) tried setting paths and reinstalling cfunits to no avail:

export LD_LIBRARY_PATH=/opt/homebrew/lib/libudunits2.0.dylib`

and

export UDUNITS2_INCDIR=/opt/homebrew/Cellar/udunits/2.2.28/include
export UDUNITS2_LIBDIR=/opt/homebrew/Cellar/udunits/2.2.28/lib
export UDUNITS2_XML_PATH=/opt/homebrew/Cellar/udunits/2.2.28/share/udunits/udunits2-common.xml

Further digging brings up to this related issue: https://github.com/orgs/Homebrew/discussions/3424.

Summary: ctypes.util.find_library() will look in /usr/lib and /usr/local/lib to find udunits2 but on newer Apple hardware libraries will be installed in /opt/homebrew instead

_libpath = ctypes.util.find_library("udunits2")

The linked thread suggest setting a symlink will solve this, but on institutional machines (like mine), I wasn't able to make this work.

I don't know if this is solvable on cfunits's side of things, but it seemed good to at least document this in case anyone else runs into this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions