简体   繁体   中英

Failed to import module found in cache

I am having a problem with a code I am running which uses a library called fenics. It runs fine on one machine but on another we get the following error:

I have no idea how to attempt to solve this and am looking for tips as to what might be going wrong here.

--- Instant: compiling ---
INFO:instant:--- Instant: compiling ---
In instant.import_module_directly: Failed to import module 'dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9' from '/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
ImportError:/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9/_dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.so: undefined symbol: _ZN6dolfin10Expression12set_propertyENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEd;
WARNING:instant:In instant.import_module_directly: Failed to import module 'dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9' from '/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
ImportError:/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9/_dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.so: undefined symbol: _ZN6dolfin10Expression12set_propertyENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEd;
Failed to import module found in cache. Modulename: 'dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
Path: '/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
ImportError:/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9/_dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.so: undefined symbol: _ZN6dolfin10Expression12set_propertyENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEd;
ERROR:instant:Failed to import module found in cache. Modulename: 'dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
Path: '/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
ImportError:/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9/_dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.so: undefined symbol: _ZN6dolfin10Expression12set_propertyENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEd;
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
~/Minimal_Magnetic_Sims/ChrisExperiment_gmsh/Calc_Magnetic_Potential.py in <module>()
     79 print('calculating U', flush=True)
     80 
---> 81 U = calc_U(params_arr, mesh, bc_markers)
     82 
     83 print('done')

~/Minimal_Magnetic_Sims/ChrisExperiment_gmsh/Calc_Magnetic_Potential.py in calc_U(params, mesh, bc_markers)
     38     M = [m*sin(theta)*cos(phi), m*sin(theta)*sin(phi), m*cos(theta)]  # Magnetic Moment
     39     vmag = [mag*sin(theta)*cos(phi), mag*sin(theta)*sin(phi), mag*cos(theta)]
---> 40     U = MagPotential(mesh,vmag,X,V,r,mu,bc_markers)
     41     print('Done for {}'.format(X), flush=True)
     42     return U

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/dolfin/functions/expression.py in __new__(cls, cppcode, *args, **kwargs)
    677                                                 [generic_function_members],
    678                                                 [mesh_function_members],
--> 679                                                 mpi_comm=kwargs.get("mpi_comm"))
    680         cpp_base, members = cpp_base[0], members[0]
    681 

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/dolfin/compilemodules/expressions.py in compile_expressions(cppargs, generic_function_members, mesh_function_members, mpi_comm)
    264         "\n\n".join(code_snippets), classnames,
    265         additional_declarations="\n".join(additional_declarations),
--> 266         mpi_comm=mpi_comm)
    267 
    268     return expression_classes, all_members

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/dolfin/compilemodules/expressions.py in compile_expression_code(code, classnames, module_name, additional_declarations, mpi_comm)
    181     compiled_module = compile_extension_module(
    182         code, additional_declarations=additional_declarations,
--> 183         mpi_comm=mpi_comm)
    184 
    185     # Get the compiled class

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/dolfin/compilemodules/jit.py in mpi_jit(*args, **kwargs)
     68         # Just call JIT compiler when running in serial
     69         if MPI.size(mpi_comm) == 1:
---> 70             return local_jit(*args, **kwargs)
     71 
     72         # Default status (0 == ok, 1 == fail)

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/dolfin/compilemodules/compilemodule.py in compile_extension_module(code, module_name, additional_declarations, additional_system_headers, mpi_comm, **instant_kwargs)
    601             code=code,
    602             additional_declarations=additional_declarations,
--> 603             **instant_kwargs)
    604 
    605     sys.stdout.flush()

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/instant/build.py in build_module(modulename, source_directory, code, init_code, additional_definitions, additional_declarations, sources, wrap_headers, local_headers, system_headers, include_dirs, library_dirs, libraries, swigargs, swig_include_dirs, cppargs, lddargs, object_files, arrays, generate_interface, generate_setup, cmake_packages, signature, cache_dir)
    584 
    585         # Import module and place in memory cache
--> 586         module = import_and_cache_module(module_path, modulename, moduleids)
    587 
    588         if not module:

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/instant/cache.py in import_and_cache_module(path, modulename, moduleids)
     90     module, e = import_module_directly(path, modulename)
     91     instant_assert(module is not None, "Failed to import module found in cache. Modulename: '%s';\nPath: '%s';\n%s:%s;" % (modulename, path, type(e).__name__,
---> 92                                                                                                                            e))
     93     for moduleid in moduleids:
     94         place_module_in_memory_cache(moduleid, module)

/scratch/ajs3g11/conda_envs/fenicsproject/lib/python3.6/site-packages/instant/output.py in instant_assert(condition, *message)
    101         _log.error(*message)
    102         text = message[0] % message[1:]
--> 103         raise AssertionError(text)
    104 
    105 

AssertionError: Failed to import module found in cache. Modulename: 'dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';
Path: '/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9';

ImportError:/scratch/ajs3g11/conda_envs/fenicsproject/.cache/instant/cache/dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9/_dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.so: undefined symbol: _ZN6dolfin10Expression12set_propertyENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEd;

When I check the location the file exists and is in the correct location.

total 96
-rw------- 1 ajs3g11 mm     0 2019-04-02 12:48 dolfin_fbfc275cbcbd922aeeb604be688cc6206a71c594.lock
drwx------ 4 ajs3g11 mm 32768 2019-04-02 12:48 dolfin_fbfc275cbcbd922aeeb604be688cc6206a71c594
drwx------ 4 ajs3g11 mm 32768 2019-04-02 17:06 dolfin_abe903615e73dfd155bc3ce45776a118093f71ff
-rw------- 1 ajs3g11 mm     0 2019-04-02 17:07 dolfin_abe903615e73dfd155bc3ce45776a118093f71ff.lock
-rw------- 1 ajs3g11 mm     0 2019-04-08 13:44 dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9.lock
drwx------ 4 ajs3g11 mm 32768 2019-04-08 13:44 dolfin_2e958ba2ca5c864d398064d4f2a072e75125d7b9```

I originally want to add comments, but I do not have enough reputations to do so. This is just a suggestion and a direction to solve the problem but not an answer to the problem. Also I am quite new to python, so there may be better ways.

You may try to debug the program using pdb https://docs.python.org/2/library/pdb.html

From your code, it is obviously that "import_module_directly" returns None and triggers the assertion

You may use your console to run pdb, set the breakpoint to the function "import_module_directly", then run by line and check what's wrong. You can check the local variables and function arguments using pdb.

我仍然不知道问题是什么或导致它的原因是什么,但是将工作环境导出到 .yml 文件中并在另一台机器上安装它解决了问题。

Even if it is late, but I want to add something here.

If you install fenics from pip, the above might be that you haven't installed cmake/gmp/mpfr packages. You can install them in Ubuntu directly by:

sudo apt install cmake gmp mpfr

You might need to have boost/vtk/openmpi/eigen installed as well, depending how the original fenics package is built. I usually built by myself, so I know what packages are required.

Most of the time the above error is due to missing some tool/package in your system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM