Fenics installation : I am lost, nothing works, I cannot even begin to test fenics


I’m trying to install fenics on Ubuntu 20.4. My goal is to use it with Pycharm.

Trial 1 :
I installed fenics with instructions : Solving PDEs in Python - <br> The FEniCS Tutorial Volume I
Installation worked well, all instructions were accepted with no error.
But the test part python -c 'import fenics' gives ModuleNotFoundError: No module named 'fenics' … why ??

Trial 2 :
using fenics documentation from fenicsproject org /download/ :
I installed fenics through what I found here fenics.readthedocs io/en/latest/installation.html#debian-ubuntu-packages
Installation worked, again. But again python -c 'import fenics' gives ModuleNotFoundError: No module named 'fenics'.

Trial 3 :
As the goal is to use it with Pycharm, I tried through Pycharm :
I installed it through pycharm settings/interpreter section : fenics is installed OK, but not recognized when I call import fenics . Following helps in forums I tried to install dijitso, dolfin, ffc, instant => but dolfin and ffc are simply impossible to find : ERROR: No matching distribution found for DOLFIN . When searching for doc about dolfin : https://fenicsproject.org/docs/dolfin/ : error 404. :cold_sweat:

I try whatever I find on forums but maybe I am wrong in my search, I mostly found solutions giving broken links…

Fenics seems to be wonderful but how one should begin with it ? From the official FEniCS Reference Manual : the “getting started” section is empty, in “todo” state :sob:
I’m lost.


Thank you for your attention and help

I can’t reproduce your error

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal

$ python3 -c "import fenics; print(fenics.__path__)"

Check you don’t have any old interfering installations, e.g. installed by pip into .local.


Could it be as simple as using python3 instead of python? The linked tutorial is somewhat outdated, and recent versions of FEniCS only support Python 3.



Thank your for your prompt help !
It was well guessed : there were several python versions.
Since I installed Anaconda, the python version used when calling “python” from a terminal was the anaconda one, and the python version where the fenics package was installed was the usr/lib/python3 one.
As it was a brand new computer I solved it basically in reinstalling ubuntu from scratch, to avoid fighting in knowing which python version was there before others. Now I’ll try to get fenics working prior to installing anything else.

Now it visibly does not work yet : I get Invalid MIT-MAGIC-COOKIE-1 key when I try python3 -c 'import fenics', but that is another story.

Thanks again

The Invalid MIT-MAGIC-COOKIE-1 is a tough one to eliminate. I’ve had it in the past, it never actually went away until I got a new computer. On the other hand, it’s mostly harmless, shouldn’t affect your calculations.

I have a similar problem. I loaded fencis per instruction into Ubuntu 20.04.3 LTS, The command python3 -c ‘import fenics’ returns ModuleNotFoundError: No module named ‘fencis’. However, if I run the program as root, everything works. I don’t think doing this is considered good operating procedure. How can I get the program to run at the user level (not as root)?

Also, when I called $ python3 -c “import fenics; print(fenics.path)” the result was “No module named ‘fenics’.” But as root, I get [’/usr/lib/python3/dist-packages/fenics’] using the same command.

It sounds like there might be some interference in your python path. Check if there is any detritus installed locally for the user, in particular in ~/.local/lib/python*/site-packages/.

Check the user’s PYTHONPATH


and also

python3 -c "import sys; print(sys.path)"

And check that user and root are in fact using the same python (python3 --version, or inspect the header when running python3 on its own). Likewise check the identity of the command itself

command -v python3

(aka, which python3)

1 Like

Hi, Fenics community
I particularly do this before using the
Fenics on Ubuntu from terminal:


Then I can do:
python3 Test-Fenics.py

Thanks for your comments. They were very helpful. The problem turned out to be the existence of two different versions of python3. Allow me to provide some commentary on this problem as it might be helpful to others. This situation came about because I had loaded a version of anaconda a while ago. This version forced the OS to boot up directly into a virtual environment. I did not pay too much attention to this because it appeared to work without any problems and it could easily be exited by a simple command. I caused a situation later by loading an updated version of python using pip. By doing this I created two versions of python coexisting on the same machine, one from the anaconda installation and one by the pip installation. I solved the problem by uninstalling anaconda. Well, sort of. In the process I corrupted the boot track on my OS installation. I’ll leave out the gory details that followed. Nevertheless, I now have an installation with one python version and the error message I originally got no longer appears. So I can now continue on to the next step in the journey. Thanks again for your prompt response.