This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

FEniCS, Eclipse and PyDev

0 votes

I have FEniCS running on my computer as well as Eclipse with PyDev for writing my Python code. However, Eclipse dose not recognize the FEniCS functions. How do I make it happen?

asked Nov 29, 2016 by sehlstrom FEniCS Novice (180 points)

2 Answers

0 votes

Hi,

I am using FEniCS 1.6 (installed from the .dmg) on MacOS 10.10 (Yosemite) and Eclipse.

First I open a fenics-shell and then I call "eclipse" from that shell.
Once you do that you should be able to run all of your script from the Eclipse GUI.

Let me know if it works for you.

Best,

U.

answered Nov 30, 2016 by umberto FEniCS User (6,440 points)

Thanks for the answer. However, I was more interested in getting Eclipse to recognize the FEniCS Python code to enable code completion and such. At the moment, all FEniCS code is marked out with red underlining implying Eclipse IDE dose not know what it means.

My Eclipse is able to recognize some (but not all) of the Fenics functions/classes.

I am not sure if "swig" class can be recognized by Eclipse or any other editor.

SWIG classes can be auto completed by adding dolfin to the "Forced Builtins" list, see my answer for details

+1 vote

You will need to do two things.

1) Configure an interpreter that can import dolfin etc. I use a shell script that sources the correct files and then executes python (see below). You can also load fenics and then start eclipse from that shell as suggested by unberto.

2) Add dolfin to the forced builtins list in the interpreter. By default PyDev parses Python code to get auto completion. This does not work for compiled modules that need to be imported and inspected to see what they contain. Numpy etc should already be on the list, see http://www.pydev.org/manual_101_interpreter.html

Here is my shell script for wrapping python with fenics, named "frun-master-python".

#!/usr/bin/bash

# Build arguments for the program from our own arguments
# Convoluted mess from the internet. Shell sucks!
CMD="exec frun-master python"
for (( i = 1; i <= $# ; i++ )); do
  eval ARG="\${$i}"
  if  [[ "$ARG" = "${ARG%[[:space:]]*}" ]]
  then
    CMD="$CMD $ARG"
  else
    CMD="$CMD \"$ARG\""
  fi
done

eval $CMD

This depends on the following script "frun-master" that can be used with python, mpirun and other commands (instant-clean, ffc etc). You must change a path inside.

#!/usr/bin/bash

# Build arguments for the program from our own arguments
# Convoluted mess from the internet. Shell sucks!
CMD="exec"
for (( i = 1; i <= $# ; i++ )); do
  eval ARG="\${$i}"
  if  [[ "$ARG" = "${ARG%[[:space:]]*}" ]]
  then
    CMD="$CMD $ARG"
  else
    CMD="$CMD \"$ARG\""
  fi
done

echo "FEniCS Master running $CMD"
source SOME∕PATH∕HERE/fenics.conf

python <<EOF
import sys, os
for p in sys.path:
    if os.path.isdir(os.path.join(p, 'dolfin')):
        print 'Using dolfin from', p
EOF

eval $CMD
answered Dec 5, 2016 by Tormod Landet FEniCS User (5,130 points)
...