Atmospheric Toolbox

Import Error with python: "dlopen(@path/_codac.so): Symbol not found _PyCObject_Type ; Referenced from: @path/_codac.so ; Expected in: flat namespace

Hi,

Here is the story:

I am working on Mac and I had previously installed coda with python2.7 but had to switch to python 3.

The python3 version working with all the installed python packages is located in
@path = “/Library/Frameworks/Python.framework/Versions/3.7/”

So I decided to install coda again, but there, using the following commands :
./configure --prefix /Library/Frameworks/Python.framework/Versions/3.7/ --enable-python PYTHON=/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

I believed it would do the job.

But, then, when I try to import coda and run coda.open I get the error mentioned in the subject hereabove (“ImportError etc.”)

I checked in the /_codac.so the dylib used (using the comand otool -L) and it gives me : ‘/usr/local/lib/libcoda.15.dylib’ and ‘/usr/lib/libSystem.B.dylib’

‘/usr/local/lib/libcoda.15.dylib’ does not correspond to @path where I have installed coda and all the dependencies, including _codac.so (and where there is also the file libcoda.15.dylib). I do not understand why the link to the dynamic library is wrong in the .so file.

If you could help me with this, I would really appreciate.

Best regards,
Quitterie

The latest version of CODA uses a cffi python interfaces (instead of a SWIG one before). This means that there is no _codac.so file anymore if you use the most recent CODA version.

Please make sure you remove completely all coda references from /Library/Frameworks/Python.framework/Versions/3.7 and install coda again.

Also, I would highly recommend to use a conda environment and install coda from conda-forge. This way you will automatically have a version that is build with HDF4 and HDF5 support (which you currently hadn’t enabled in your own coda build).

Thank you for your answer.
I removed all coda references as well as python references and downloaded the anaconda package.
Now, when I want to use conda to install coda (conda install -c conda-forge coda), it cannot solve the environment… It told me it was looking for conflicts, which took several hours and then said “Found conflicts! Looking for incompatible packages.” Then bascially listed all the conflicts, which are so numerous it looks like the packages are all incompatible, and that is it ! I still don’t have coda.

Try to install it in its own conda environment. e.g.:

$ conda create -n coda
$ conda activate coda
$ conda install -c conda-forge coda

Be aware that trying to install packages from conda-forge in a conda environment where all other packages do not also come from conda-forge will very often result in conflicts.

Is it important to use conda-forge instead of stcorp to install coda ? (except that weardly enough, when I tried to install coda using stcorp previously, it installed an old coda version - 2.21 - and then, I would get an error when trying to use coda.open (‘unsupported file type’ → as if I did not have the correct CODADEF file, which I had and I had also made sure to give the program the correct path to the codadef file…)
So, since I had this error, I removed all the coda files and tried installing coda again using conda-forge, which lead me to the problem I mentioned earlier.
And now, I tried to re-install coda using a conda environment and it worked so well I simply want to give up working on Aeolus data and quit my shitty job:

  • First, during installation, I get this message : “Verifying transaction: | WARNING conda.core.path_actions:verify(962): Unable to create environments file. Path not writable.”
  • Second, of course, now, if I want to import the coda library, I have to be in the coda environment, for which conda-forge automatically installed python3.10 (when the basic anaconda python is 3.8)
  • Obviously in this environnement I have to import again all the python packages I will need (so basically to duplicate them on my computer, smart!)
  • Therefore I had to re-install netCDF4 and h5py (I used conda-forge since I was in the coda environment where I had previously used conda-forge to install coda) and – you won’t believe me – it worked for netCDF4 (still had this warning about path not writable, though) but not for h5py !! conflicts again !!!

You can actually create a conda environment using a specific python version. Just recreate the conda environment from scratch and use

$ conda install -c conda-forge coda python=3.8

will this solve the conflicts ?

Thank you very much for your help, Sander, it did solve the conflicts.
Sorry to bother you again, I still have a problem when trying to open a file, using coda.open (‘unsupported file type’). And yet, I used the command: os.putenv(‘CODA_DEFINITION’, ‘path_to_the_codadef_files’) and I downloaded all the AEOLUS.codadef files for year 2021 (AEOLUS-20210310, AEOLUS-20210806, AEOLUS-20211103). I am interested in the september 2021 Aeolus data.

You only need the latest codadef (it supports all known versions of the Aeolus data formats).

Where exactly did you install the .codadef file (with directory on your system)?
And did you actually use that directory as argument to os.putenv (or did you literally use ‘path_to_the_codadef_files’)?

the command line is
os.putenv(‘CODA_DEFINITION’, ‘/Users/cazenave/opt/anaconda3/envs/coda/share/definitions/’)
In the coda environment, the python I use is the following /Users/cazenave/opt/anaconda3/envs/coda/bin/python

That seems Ok. And you then also have /Users/cazenave/opt/anaconda3/envs/coda/share/definitions/AEOLUS-20211103.codadef?

Which specific file are you trying to open with coda.open?

Yes, I have /Users/cazenave/opt/anaconda3/envs/coda/share/definitions/AEOLUS-20211103.codadef
I am trying to open this file : AE_OPER_ALD_U_N_2B_20210908T072144_20210908T085220_0001.DBL

And the actual error message is actually “coda.CodacError: coda_open(): unsupported product file” (and not ‘unsupported file type’)…

Are you actually performing the putenv before you are importing coda as it says in the documentation?

This works fine for me:

import os
os.putenv('CODA_DEFINITION', '/Users/sander/miniconda3/envs/coda/share/coda/definitions')
import coda

with coda.open('/Users/sander/Downloads/AE_OPER_ALD_U_N_2B_20210908T072144_20210908T085220_0001.DBL') as product:
    print(product.fetch('mph/product'))

Indeed, I’d put it after. Now, it is working, thanks !