1

I want to install fenics in Ubuntu 20. First I made a python environment using:

sudo apt install python3-venv

Then inside the folder I want to make an environment I open a terminal and use:

python3 -m venv myproject

myproject is the name of the environment I made.

I then activate my environment:

source myproject/bin/activate

To install fenics for this particular environment while I activated the environment, I use:

pip install fenics

I verify the installation using pip list which returns:

Package        Version       
-------------- --------------
fenics         2019.1.0      
fenics-dijitso 2019.1.0      
fenics-ffc     2019.1.0.post0
fenics-fiat    2019.1.0      
fenics-ufl     2019.1.0      
mpmath         1.1.0         
numpy          1.19.4        
pip            20.0.2        
pkg-resources  0.0.0         
setuptools     44.0.0        
sympy          1.7.1 

I try to import fenics using:

python -c "import fenics"

But I get the error below stating there is not fenics module:

raceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'fenics'

What is the problem? Hopefully, after successful installation of fenics, I can install Spyder and other python packages and will be able to use fenics inside spyder.

Edit I want to install fenics in a python virtual environment.

MOON
  • 2,516
  • 4
  • 31
  • 49

3 Answers3

1

The issue here is that fenics is just a meta-package and it does not contain any library that you can use in your Python code.

Quoting from the README for the fenics project :

This package contains a single file, setup.py, that allows all of the FEniCS Python components to be installed from PyPI using pip:

pip3 install fenics

Actual use of the library is done via

import ffc

All different components are under this package. For example, fenics-fiat is available as ffc.fiatinterface.

Amit Singh
  • 2,875
  • 14
  • 30
  • Thanks! I can import fenics the way you mentioned, but I cannot run the examples from fenics. It seems it has problem with the `UnitSquareMesh` becuase it cannot find it. The example: https://github.com/hplgit/fenics-tutorial/blob/master/pub/python/vol1/ft03_heat.py – MOON Jan 05 '21 at 13:52
  • 1
    There are two version of `fenics`. The one you have installed via `pip` is the one which is the "older" version which is in a BitBucket repo, the newer, actively developed version is on Github on which I guess the tutorial is based, and can be installed via Ubuntu as per [this official page](https://fenics.readthedocs.io/en/latest/installation.html#debian-ubuntu-packages) – Amit Singh Jan 05 '21 at 14:30
0

Fenics library of python

If you have installed pip than you have to use pip install fenics. If you have installed pip3 than `pip3 install fenics

enter image description here

enter image description here

I have already installed both.

sudo apt update
sudo apt install python3-pip

Install pip for Python 2 with:

sudo apt install python-pip
0

After doing pip3 install fenics,write python3 -c import ffc to import it. If this works, it has been imported. It is called ffc, not fenics

Aarav Garg
  • 21
  • 1
  • 5