Error running Demo code

I installed Fenics on Windows Subsystem for Linux (Ubuntu 18.04), using

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install --no-install-recommends fenics

I tried to run demo code ft01_poisson.py

from fenics import *
import matplotlib.pyplot as plt
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)

but first I got an error importing matplotlib, which I solved by installing it through

sudo apt-get install python3-matplotlib

(I’m running the demo code in Python3).
Then I got and error with FunctionSpace, which was solved adding

from dolfin import *

in the preamble (I don’t know if it was the right way to solve it).
After that I got the following error at Expression line

>>> u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/dolfin/jit/jit.py", line 167, in compile_class
    mpi_comm=mpi_comm)
  File "/usr/lib/python3/dist-packages/dolfin/jit/jit.py", line 47, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dolfin/jit/jit.py", line 103, in dijitso_jit
    return dijitso.jit(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/dijitso/jit.py", line 178, in jit
    params)
  File "/usr/lib/python3/dist-packages/dijitso/build.py", line 153, in build_shared_library
    status, output = get_status_output(cmd)
  File "/usr/lib/python3/dist-packages/dijitso/system.py", line 41, in _get_status_output_subprocess
    stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'c++': 'c++'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dolfin/function/expression.py", line 376, in __init__
    self._cpp_object = jit.compile_expression(cpp_code, params)
  File "/usr/lib/python3/dist-packages/dolfin/function/jit.py", line 158, in compile_expression
    expression = compile_class(cpp_data, mpi_comm=mpi_comm)
  File "/usr/lib/python3/dist-packages/dolfin/jit/jit.py", line 170, in compile_class
    raise RuntimeError("Unable to compile C++ code with dijitso")
RuntimeError: Unable to compile C++ code with dijitso

Thanks in advance for any clue.

It looks like you do not have a C++ compiler installed on your system. Try running sudo apt install build-essential to install it.

1 Like

Thank you.
I faced the same error, and it is solved via your answer.

To get rid of this error you can try using os.listdir() function to check that at least python sees the file exists or not.