python – Error “ImportError: dlopen” with “hi_classy.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace ‘___kmpc_barrier'”

One sent me a notebook Python script that I launch by doing :

$ jupyter-lab example.ipynb

Everything works fine in the running by step the script.

Now, I would like to get from this .ipynb file a pure python file that I could execute like a classic script.

For this, I tried 2 things :

I) $ jupyter-nbconvert example.ipynb –to python

If I execute the example.py, I get the error below :

from hi_classy import Class
ImportError: dlopen(/Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '___kmpc_barrier'

II) Another error after doing: $ ipynb-py-convert example.ipynb example.py

$ python3.9 example.py

%matplotlib inline
    ^
SyntaxError: invalid syntax

III) Even if with ipython from /opt/intel/oneapi/intelpython/latest/bin/ipythonI get errors.

Conclusion : I have an issue when I do importing in the following Python script :

from hi_classy import Class
import matplotlib.pyplot as plt
import numpy as np

# Working
parameters = {
    'Omega_Lambda': '0.',
    'Omega_fld': '0.',
    'Omega_smg': '-1.',

...

I get at the execution with python3.9 from Intel OneAPI 2022 ( python=/opt/intel/oneapi/intelpython/latest/bin/python3.9 ) the following error :

Traceback (most recent call last):
  File "/Users/stefan/example.py", line 1, in <module>
    from hi_classy import Class
ImportError: dlopen(/Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '___kmpc_barrier'

I can’t explain this error since in python3.9 shell, I have no error when I do :

Python 3.9.7 (default, Oct 26 2021, 21:00:26)
[Clang 10.0.0 ] :: Intel Corporation on darwin
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
(.startup.py)
(imported os)
(imported sys)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported glob)
(imported re)
>>> from hi_classy import Class
>>>

that is to say, I have no errors.

I try to go deeper and did a : $ otool -L hi_classy.cpython-39-darwin.so

that gives :

$ otool -L /Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so
/Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so:
    @rpath/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.0.0)

and also did a :

$ otool -l /Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so

that gives :

/Users/stefan/.local/lib/python3.9/site-packages/hi_classy.cpython-39-darwin.so:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 552
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x00000000002b4000
  fileoff 0
 filesize 2834432
  maxprot 0x00000005
 initprot 0x00000005
   nsects 6
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000000001fc0
      size 0x00000000001a6258
    offset 8128
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x00000000001a8218
      size 0x0000000000000474
    offset 1737240
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x00000000001a868c
      size 0x000000000000077c
    offset 1738380
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x00000000001a8e20
      size 0x000000000002f131
    offset 1740320
     align 2^5 (32)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __TEXT
      addr 0x00000000001d7f80
      size 0x000000000007fb80
    offset 1933184
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x0000000000257b00
      size 0x000000000005c4f0
    offset 2456320
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 632
  segname __DATA
   vmaddr 0x00000000002b4000
   vmsize 0x0000000000024000
  fileoff 2834432
 filesize 147456
  maxprot 0x00000003
 initprot 0x00000003
   nsects 7
    flags 0x0
Section
  sectname __nl_symbol_ptr
   segname __DATA
      addr 0x00000000002b4000
      size 0x0000000000000008
    offset 2834432
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 190 (index into indirect symbol table)
 reserved2 0
Section
  sectname __got
   segname __DATA
      addr 0x00000000002b4008
      size 0x0000000000000190
    offset 2834440
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 191 (index into indirect symbol table)
 reserved2 0
Section
  sectname __la_symbol_ptr
   segname __DATA
      addr 0x00000000002b4198
      size 0x00000000000005f0
    offset 2834840
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000007
 reserved1 241 (index into indirect symbol table)
 reserved2 0
Section
  sectname __mod_init_func
   segname __DATA
      addr 0x00000000002b4788
      size 0x0000000000000008
    offset 2836360
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000009
 reserved1 0
 reserved2 0
Section
  sectname __data
   segname __DATA
      addr 0x00000000002b47c0
      size 0x0000000000020080
    offset 2836416
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __bss
   segname __DATA
      addr 0x00000000002d4840
      size 0x00000000000022a8
    offset 0
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Section
  sectname __common
   segname __DATA
      addr 0x00000000002d6b00
      size 0x0000000000000038
    offset 0
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x00000000002d8000
   vmsize 0x0000000000028000
  fileoff 2981888
 filesize 148928
  maxprot 0x00000001
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 3
            cmd LC_DYLD_INFO_ONLY
        cmdsize 48
     rebase_off 2981888
    rebase_size 1208
       bind_off 2983096
      bind_size 944
  weak_bind_off 0
 weak_bind_size 0
  lazy_bind_off 2984040
 lazy_bind_size 4656
     export_off 2988696
    export_size 13024
Load command 4
     cmd LC_SYMTAB
 cmdsize 24
  symoff 3003448
   nsyms 3508
  stroff 3061304
 strsize 69512
Load command 5
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 2606
     iextdefsym 2606
     nextdefsym 668
      iundefsym 3274
      nundefsym 234
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 3059576
  nindirectsyms 431
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 6
     cmd LC_UUID
 cmdsize 24
    uuid C287678B-64EF-3DE0-8D1E-12DE60976E7B
Load command 7
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.10
      sdk 10.17
Load command 8
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 9
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name @rpath/libc++.1.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1.0.0
compatibility version 1.0.0
Load command 10
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1311.0.0
compatibility version 1.0.0
Load command 11
          cmd LC_RPATH
      cmdsize 88
         path /opt/intel/oneapi/compiler/2022.0.0/mac/bin/intel64/../../compiler/lib (offset 12)
Load command 12
          cmd LC_RPATH
      cmdsize 56
         path /opt/intel/oneapi/intelpython/latest/lib (offset 12)
Load command 13
          cmd LC_RPATH
      cmdsize 56
         path /opt/intel/oneapi/intelpython/latest/lib (offset 12)
Load command 14
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 3001720
 datasize 1728
Load command 15
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 3003448
 datasize 0

What could I try to fix this error ?

I have been looking for the message “symbol not found in flat namespace '___kmpc_barrier” but without success on the web.

Maybe this is related to OpenMP of Intel but I am not 100% sure.

Update

It is really weird and I can’t explain it for the moment but if I do, in my script, before importing hi_classy :

import numpy as np
import matplotlib.pyplot as plt
from hi_classy import Class

Then, I have no errors then and the script works fine.

Have I got to conclude that hi_classy needs to “know” numpy and matplotlib libraries before being loaded ?

Leave a Comment