error on import of iris in windows: UDUNITS-s XML "no such file or directory"

427 views
Skip to first unread message

Dan Codiga

unread,
Aug 12, 2016, 8:11:05 AM8/12/16
to Iris
I'm using Anaconda python (v2.7) on Windows 7 and Navigator tells me iris 1.9.2 is installed in my virtual environment. Other packages import fine, and my setup/system is otherwise stable and reliable.

When I import iris I get this error:

 OSError: [UT_OPEN_ARG] Failed to open UDUNITS-2 XML unit database : "No such file or directory"

There was an earlier discussion here,

https://groups.google.com/d/msg/scitools-iris/3R_yYt55RkE/YbBTHTJfAAAJ

about what is apparently the very same issue.

(Am creating a new discussion mainly to give it a more specific subject line, and also to bump/freshen it.)

What is the latest thinking on how to solve this problem? I read through the earlier discussion but either I missed it, or a clear solution hadn't yet been described.

Dan Codiga

unread,
Aug 26, 2016, 10:38:31 AM8/26/16
to Iris
OK so I finally understood the solution from that prior post-- and it does work for me.

Within a given commandline interface session (i.e. python or iPython console), the first import of iris must occur when the working directory is on the C: drive. Subsequent imports of iris will work fine no matter what the working directory is, for example it can be on a network shared drive (I typically use a working directory on a shared drive).

If you try to import iris the first time when the working directory is on a shared drive and not the local drive C:, you get the error. That's what was happening for me.

Issue solved. To the folks who made those earlier posts, thank you.

Simon Tett

unread,
Jan 21, 2017, 6:53:40 AM1/21/17
to Iris
So I upgraded from iris 1.92 to 1.10 on Windows 64 on Conda and the trick of:
 os.setcwd('c:')
import iris
fails with:
OSError: [UT_PARSE] Failed to open UDUNITS-2 XML unit database : "No such file or directory"


After some digging I tracked this down to a problem in cf_units  and presumably how Ananconda installs packages,

I needed to edit C:\Anaconda2\Lib\site-packages\cf_units\__init__.py to modify line 378 to
_alt_xml_path = os.path.join(sys.prefix, 'Library','share',

from

_alt_xml_path = os.path.join(sys.prefix, 'share',

then the old hack works...

It would be good if someone more skilled than I in python could fix cf_units so

1) It looks for udunits2.xml file in sensible **places**.
On my system that is
os.path.join(sys.prefix, 'Library','share', 'udunits', 'udunits2.xml')
but I imagine different systems make different choices,,

2) fixes the need to do os.setcwd('c:) & import cf_units

I note the code comments in cf_units refer to

UDUNITS2_XML_PATH env variable -- but I see no reads of this env variable in the __init__.py file.

Simon

Reply all
Reply to author
Forward
0 new messages