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

Running a .py file that imports from dolfin on command line produces error that doesn't occur in ipython or IDLE

0 votes

Hi all,

I recently installed fenics 2016.10 on Ubuntu 16 according to the instructions under the section entitled "Ubuntu packages (stable release)" here:
https://fenicsproject.org/download/.

All of my programs run as expected when I run them through ipython. Additionally, they run fine from the IDLE and Spyder. In order to improve the performance of my code, I recently started attempting to get my code to run in parallel using Open MPI. I found to do this, I need to my program from the command line.

Instead of the standard "python my_script.py" command, I simply needed to add "mpiexec -n 4 python my_script.py". Here 4 is the number of cores on my laptop. Both commands, however, produce an import error: "no module named dolfin."

As suggested in the comments for this question: https://fenicsproject.org/qa/8648/no-module-named-dolfin-on-ubuntu-14-10, I tried in my terminal

/usr/bin/python
import dolfin

However, this does NOT return an error as the commenter in the link above suggests. Does anyone know what might be going on here?
Thank you in advance.
Best,
-Sean

asked Aug 23, 2016 by carney340 FEniCS Novice (160 points)
edited Aug 23, 2016 by carney340

How did you install FEniCS? You say that you followed the instructions at https://fenicsproject.org/download/ for installing FEniCS but there are at least four different methods listed on that page. Which one did you use?

Hi johannr, I should have specified this in the original post, and accordingly I have edited it. I installed it as instructed under the section "Ubuntu packages (stable release)" with the commands:

sudo add-apt-repository ppa:fenics-packages/fenics
sudo apt-get update
sudo apt-get install fenics
sudo apt-get dist-upgrade

Thanks,
-Sean

This means that when you run python it is not the same as /usr/bin/python. What do you get when you run which python?

You might get your script to run in parallel by using mpiexec -n 4 /usr/bin/python my_script.py.

The command "which python" returns /home/sean/anaconda2/bin/python. I am guessing that to make this work I should look at suggestion #3 in the comment by maartent in the link:

https://fenicsproject.org/qa/8648/no-module-named-dolfin-on-ubuntu-14-10,

Also, your suggestion to run mpiexec -n 4 /usr/bin/python my_script.py worked! Thank you for the suggestion.

...