Installing cf-python error

Hi,

I am using a python virtual environment and have installed cf-python using pip install cf-python. When running import cf in spyder I receive the following message:

Traceback (most recent call last):

File “/tmp/ipykernel_18462/2405381555.py”, line 1, in <cell line: 1>
import cf

File “/home/thomas/Documents/Python/nemo_unagi/lib/python3.9/site-packages/cf/init.py”, line 126, in
import cfunits

File “/home/thomas/Documents/Python/nemo_unagi/lib/python3.9/site-packages/cfunits/init.py”, line 47, in
from .units import Units # noqa: F401

File “/home/thomas/Documents/Python/nemo_unagi/lib/python3.9/site-packages/cfunits/units.py”, line 41, in
raise FileNotFoundError(

FileNotFoundError: cfunits requires UNIDATA UDUNITS-2. Can’t find the ‘udunits2’ library.

I can see in the directory of the virtual environment ‘lib/python3.9/site-packages/cfunits/etc’ that ‘udunits’ exists. Could you advise how I can go about making cf-python work?

I have even tried manually installing udunits in ‘site-packages’, but to no avail.

Thanks
Thomas

Hi Thomas,

Have you set LD_LIBRARY_PATH to point to the location of the libudunits2.so.0 ?
https://ncas-cms.github.io/cf-python/installation.html#unidata-udunits-2-library

Cheers,
Ros.

Hi Ros,

After some meddling about I’ve got it working. Instead of modifying LD_LIBRARY_PATH, I just made a symbolic link to the location of libudunits2.so.0. Happy days.

Cheers
Thomas

Hi Thomas,
Just in case someone else comes across this when searching on the helpdesk the method I use is to use a Miniconda install and do:
conda install -c conda-forge pip udunits2 cartopy
conda install cf-python cf-plot

Cheers
Andy