cannot import iris from python script

1,558 views
Skip to first unread message

David Simonin

unread,
Dec 4, 2012, 5:28:50 PM12/4/12
to scitoo...@googlegroups.com
I ran the following command:
 sudo python setup.py install

It seems that the installation when ok (no error), but I cannot import iris from any python script.
$ python
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import iris
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named iris
>>>

What am I doing wrong or missing?

RHattersley

unread,
Dec 5, 2012, 4:06:35 AM12/5/12
to scitoo...@googlegroups.com
Hi David,

Could it be the root user is using a different python from your normal user account? If that were the case, Iris would have been installed into the wrong python environment.

To check, try typing the following:

$ sudo which python

$ which python

If they're different you probably just need to do:
$ python setup.py install
(i.e. without the "sudo" part)

Richard

David Simonin

unread,
Dec 5, 2012, 4:57:50 AM12/5/12
to scitoo...@googlegroups.com
Hi Richard

I had to use:
$ sudo python setup.py install
as the installation was requesting some access to /usr/....

After the installation every IRIS stuff (bin and build folder) were created in the same place that the iris source.
So I did not really understand why, the installation requested access to /usr/... folder and did not put iris with the other python packages like it was done for cartopy.

David


Phil Elson

unread,
Dec 5, 2012, 10:03:58 AM12/5/12
to scitoo...@googlegroups.com
Hmm, I'm not entirely sure what the problem is here (other than the possibility, as Richard says, that sudo's python is different to your user's python).
Did you try giving the absolute python path for the sudo command? Something like:

$> PYTHON_LOCATION=$(which python)
$> echo $PYTHON_LOCATION
$> sudo $PYTHON_LOCATION setup.py install

Another way of getting this to work is to use avoid having iris installed in "/usr/...". This can be done with:

python setup.py install --user

On my machine, that translates to "~/.local/lib/python2.7/site-packages/".

The setup.py included with Iris is a python standard distutils implementation (with a couple of enhancements) - so I would expect all python packages that you install to have the same problem (I'm surprised cartopy worked but Iris didn't).

Hope my two possible solutions at least enable you to be temporarily "import iris"!

All the best,

Phil


David Simonin

unread,
Dec 6, 2012, 10:52:37 AM12/6/12
to scitoo...@googlegroups.com
Nothing that has been suggested work. and yes my python from sudo and user is the same.

I am doing:
  1 - git clone https://github.com/SciTools/iris.git
output:
Cloning into 'iris'...
remote: Counting objects: 6577, done.
remote: Compressing objects: 100% (1871/1871), done.
remote: Total 6577 (delta 4283), reused 6352 (delta 4101)
Receiving objects: 100% (6577/6577), 50.48 MiB | 1.32 MiB/s, done.
Resolving deltas: 100% (4283/4283), done.
  2 -  cd into iris folder
  3 - running install command (any of the following command gave the same result)
python setup.py install  (with and without sudo)
python setup.py insatll --user (with and without sudo)
output see attach file (using python setup.py insatll --user)
there are some warning:
 warning: no previously-included files matching '*' found under directory 'docs/iris/build'
 warning: no files found matching '*.cc' under directory 'src'
 warning: no files found matching '*.cpp' under directory 'src'
 warning: no files found matching '*.h' under directory 'src'
 error: None

nothing is but in ~/.local/lib/python2.7/site-
packages/

if I create a symbolic link from iris/lib/iris to  ~/.local/lib/python2.7/site-
packages/ and import iris from python. I have the following error:

>>> import iris
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "iris/__init__.py", line 100, in <module>
    import iris.cube
  File "iris/cube.py", line 35, in <module>
    import iris.analysis
  File "iris/analysis/__init__.py", line 38, in <module>
    import iris.coords
  File "iris/coords.py", line 34, in <module>
    import iris.aux_factory
  File "iris/aux_factory.py", line 28, in <module>
    from iris._cube_coord_common import CFVariableMixin, LimitedAttributeDict
  File "iris/_cube_coord_common.py", line 24, in <module>
    import iris.unit
  File "iris/unit.py", line 181, in <module>
    _lib_ud = ctypes.CDLL(_lib_ud, use_errno=True)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libudunits2.so.0: cannot open shared object file: No such file or directory
>>>
So suspect that the installation is failing, but I cannot see what I am missing?
Any idea??








output.txt

bblay

unread,
Dec 10, 2012, 8:13:23 AM12/10/12
to scitoo...@googlegroups.com
It sounds like you're very close indeed, and just need access to udunits2.
Are you able to see libudunits2.so.0 anywhere on your system?

bjlittle

unread,
Dec 10, 2012, 8:34:18 AM12/10/12
to scitoo...@googlegroups.com
Hi David,

For S.I units support Iris requires Unitdata UDUNITS-2 (see ftp://ftp.unidata.ucar.edu/pub/udunits/udunits-2.1.24.tar.gz)

Build and install UDUNITS-2 on your installation. Please note where the resulting libudunits2.so is installed. You can
control the location of the install target directory for this shared library i.e.

Linux> mkdir download
Linux> cd download
Linux> wget ftp://ftp.unidata.ucar.edu/pub/udunits/udunits-2.1.24.tar.gz
Linux> tar xzvf udunits-2.1.24.tar.gz
Linux> cd udunits-2.1.24
Linux> ./configure --prefix=<TARGET-DIR>
Linux> make
Linux> make install

Note that you can choose not to exercise the "--prefix" option and install to the system default directory; probably /usr/local/lib.

Then within your Iris Git directory:

Linux> cd lib/iris/etc
Linux> cat > site.cfg <<EOF
[System]
udunits2_path = <TARGET-DIR>/libudunits2.so
EOF

The site.cfg configuration file tells Iris where to find the UDUNITS-2 shared library.

Hope this helps!




David Simonin

unread,
Dec 10, 2012, 3:07:26 PM12/10/12
to scitoo...@googlegroups.com
Aleluya!!!!! It is working... Thank everyone for you help.
It is working.
And you were rigth I was missing the UDUNITS-2 shared library.
However I would to say for my defence that I had downloaded the source file and unpacked it. Everything was ready.... and then I forgot to install it.

I am in Exeter this Wednesday. I am planning to see you in the morning with a massive list of (silly) quetsions.
Regards
David
Reply all
Reply to author
Forward
0 new messages