Installation problems

Hello, I’ve tried to install fenics and use the repository of the paper “Hybrid FEM-NN models: Combining artificial neural networks with the finite element method]” to calculate a linear Physics-Informed Neural Network.

I’m using Windows 11 and Python 3.10.4.

To run the script main.py I need to use the fenics package. As usual working in python I did

pip install fenics

which worked without any problems. Trying to run the script prompted the error

from fenics import *
ModuleNotFoundError: No module named 'fenics'

After reading a couple of posts on this issue I made sure there are no other virtual environments anymore and that the path sys.path :

C:\Users\neuma\AppData\Local\Programs\Python\Python310\Lib\site-packages

contains the folder which contains the installed fenics packages:

fenics_dijitso-2019.1.0.dist-info
fenics_ffc-2019.1.0.post0.dist-info
fenics_fiat-2019.1.0.dist-info
fenics_ufl-2019.1.0.dist-info
fenics-2019.1.0.dist-info

I’ve noted that there is no folder named just fenics.

After this attempt did not work I tried to follow the instruction for DOLFINx (Installation — DOLFINx 0.5.1.0 documentation) since some posts mentioned dolfinx and fenics are the same.

After installing the docker I followed the instructions on running fenics within the docker (2. Introduction — FEniCS Containers 1.0 documentation). This at least seemed to work using the Terminal:

C:\Users\neuma>docker run -ti quay.io/fenicsproject/stable:latest
# FEniCS stable version image

Welcome to FEniCS/stable!

This image provides a full-featured and optimized build of the stable
release of FEniCS.

To help you get started this image contains a number of demo
programs. Explore the demos by entering the 'demo' directory, for
example:

cd ~/demo/python/documented/poisson
python3 demo_poisson.py
fenics@9548d966c2fc:~$ cd ~/demo/python/documented/poisson
fenics@9548d966c2fc:~/demo/python/documented/poisson$ python3 demo_poisson.py
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Solving linear variational problem.
To view figure, visit http://0.0.0.0:8000
Press Ctrl+C to stop WebAgg server

Visiting the url prompt the following message:

This page is not working
0.0.0.0 has not sent any data.
ERR_EMPTY_RESPONSE

Since I seem to have tried all possible versions of installation of fenics (and/or Dolfinx) and nothing worked I want to ask here if anyone could help me with the installtion.

If you need any more information just let me know. Would be great if someone could help me out.

Oskar

As you can see here, the code runs:

but you have not enabled port forwarding Explore networking features on Docker Desktop | Docker Docs
See for instance
5. Running Jupyter notebooks — FEniCS Containers 1.0 documentation

Hey dokken, thank’s for the reply. Well this example was just meant as proof of function on my computer. Actually I want to use python code within the IDE PyCharm.

There, the package fenics is not working and I can’t really understand why. Since the package seems ot be installed at the used environment (see the listed package folders).

Also it seems like I would be running the script demo_poisson.py online since I cannot find it on my computer. I’m pretty confused about how to understand the difference betweend fenics and dolfinx and why I need Ubuntu or Linux and a Docker to run a package which already seems to be installed in python . Maybe this screenshot will make it a little clearer:

So if I just try to get fenics running somewhere (does not have to the python IDU PyCharm) I will need to enable port forwarding as explained here 5. Running Jupyter notebooks — FEniCS Containers 1.0 documentation. When I enter the command

docker run --name notebook -w /home/fenics -v $(pwd):/home/fenics/shared -d -p 127.0.0.1:8888:8888 quay.io/fenicsproject/stable 'jupyter-notebook --ip=0.0.0.0

in my Windows Terminal I get the following message:

docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.

Could you maybe help me on that one?

Greets
Oskar

You only need the port forwarding if you want to use the plotting interface.
See for instance Mount current directory as a volume in Docker on Windows 10 - Stack Overflow
It could also be an issue depending on the path on your system. Does it include spaces or any special characters ?

You can also see; Share directory in docker ( windows 10 platform ) - #4 by dokken
or How to use pyvista in Docker for Windows 10 user

Which path do you mean?

The current working directory is C:\Users\neuma>. So there are no special characters or spaces.

I am not sure if I’ve understood all problems (since there seem to be more than one), but if from fenics import * doesn’t work, even if you have it installed, try from dolfin import * (or dolfinx or fenicsx).

After a long while of confusion, some years ago I found out that the python-module fenics is apparently just a dummy package and alias for dolfin, which is the true interface. And it seems to be some kind of gamble whether the fenics-alias is installed or not, depending on the source you’re installing it from…

Hey welahi, thank’s for the reply and please excuse my confusing post. My basic goal is to make use of the Fenics package within Windows. Any way is welcomed now. But there seem to be a couple of different ways and some complications with those as well.

Concering your second paragraph: This would make a lot of sense since the mentioned fenics-(sub)folders contain no executables.

No problem, mate, I know myself how confusing the setup can be. Could you maybe answer the following question so that we can find the best way to help you?

  1. Does import dolfin on your computer work? I mean outside of docker, on your Windows machine, in a regular python shell. Further does any of import fencisx or dolfinx work?
  2. Your main goal is to get the code from the paper running, correct? I took a quick look at the paper but couldn’t find out what version of fenics they are using, do you maybe know more?
  3. What does pip show fenics say? Which version is installed?

Keep in mind that fenics and fenicsx are two completely different beasts. Even the different fenics versions may differ widely.

In my experience, there are these ways to get fenics running:

  1. Use docker (because inside of docker everything is installed and just works).
  2. Use pip (may or may not work)
  3. Use conda (works most of the time).
  4. Compile it yourself

Questions:

  1. No and no
  2. Yes. The corresponding script in github was last changed 12 months ago. Regarding fenics · PyPI this would mean they (maybe) used version 2019.1.0 (couldn’t find a proper release history from the official fenics homepage)
  3. I have fenics version 2019.1.0 (in accordance to pypi) installed

Solutions:

  1. The docker seems to work as described by dokken but I do not understand how to work independently (call my own functions, plot results, etc.)
  2. Only pip install fenics did not prompt an error but still not working (as you just mentioned it’s more or less a dummy package)
  3. Can you recommend a tutorial on that one?
  4. Same like 3.

Thank’s!

Okay, I really don’t know why your pip-installation doesn’t work, but at some point I just gave up the setup with pip.

To the methods:

  1. See below
  2. It’ll stay a mystery
  3. Install miniconda or anaconda on your system and follow the setup instructions. After that, install fenics via conda using conda install -c conda-forge fenics. It’s worth a try if you’re willing to ‘waste’ some space on your hard drive.
  4. Look, I enjoy pain just as every other masochist out there, but even I wouldn’t want to try to compile fenics on Windows.

Docker:

Did you read dokken’s links? They should basically cover everything you need. Short version: Every docker container is like a little, isolated mini-os, with it’s own file system and programs. If you want your container to be able to communicate with the outside world, you need to tell this docker.

I suggest that before you start with the fancy stuff, try to mount a path into your container. Create somewhere a directory on your Windows machine (e.g. C:\Users\Oskar\fenics or whatever Windows uses as home directories). Find some directory in the container, which already exists (for example the demo-directory), but get the whole path (i.e. without the ~, but /the/absolute/path/to/demo). Then start the container via docker run --rm -it -v C:\Users\Oskar\fenics:/the/absolute/path/to/demo quay.io/fenicsproject/stable:latest. This way, every file you copy into C:\Users\Oskar\fenics will be visible in your container.

2 Likes

Ok, thank’s for letting me know the installation is generally really hard. At least now I know I’m just regular incompetent and not really incompetent.

Seems like 2. and 4. shouldn’t be investigated any further for now. Unfortunately 3. using miniconda prompts the following:

(base) C:\Users\neuma>conda install -c conda-forge fenics
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - fenics

Current channels:

  - https://conda.anaconda.org/conda-forge/win-64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

So going with the Docker Method I try to mount a local directory into my container with

C:\Users\neuma>docker run --rm -it -v C:\Users\neuma\fenics:C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

or

C:\Users\neuma>docker run --rm -it -v C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

or using dokken’s link

C:\Users\neuma>docker run --rm -it -v %cd%:C:\Users\neuma\fenics\hybrid-fem-nn-examples-main\examples\pinn_linear\main.py
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

or

C:\Users\neuma>docker run --rm -it -v %cd%:C:\Users\neuma\fenics
"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

which doesn’t work. Do you know what I’m doing wrong? My understanding is that I only want to launch a docker inside a specific directory that contains pyhton files?! Unfortunately the before mentioned example code is used from an online repository Quay and not started from a local folder.

Concerning this line from dokken, I’ve tried including to the best of my understanding the information here Explore networking features on Docker Desktop | Docker Docs to do Port Mapping (again, I don’t really now what this means, apart from sending info to an URL) via the following modification:

Instead of

docker run -ti quay.io/fenicsproject/stable:latest

I use

docker run -p 80:80 -ti quay.io/fenicsproject/stable:latest
or
docker run -p 8000:80 -ti quay.io/fenicsproject/stable:latest

as recommended which also doesn’t do the trick of letting me see the visualization of the results of demo_poisson.py in a webbrowser nor leads me any further to how to run my own scripts in a local directory. I’m pretty lost on that one to be honest…

You are not understanding what -v does.
-v mountains a volume (shares a directory from your system) with the container.

This means that running the following in powershell

docker run -ti -v ${PWD}:/home/shared quay.io/fenicsproject/stable:latest

will share the current directory with the container, and in the container the folder will be found at /home/shared
See for instance

and

No, I don’t understand what -v means. I’m pretty new to docker and I hoped I could just find a procedur to execute scripts and avoid getting deeper into docker itself.

I’ve tried the following in Windows PowerShell (run as admin):

PS C:\Windows\system32> docker run -ti -v $(PWD):/home/shared quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Windows\system32> docker run -ti -v $(PWD): C:/Users/neuma/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.
PS C:\Windows\system32> docker run -ti -v $(PWD): C:/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.

Also I tried the normal Windows Terminal and got this:

C:\Users\neuma>docker run -ti -v $(PWD):/home/shared quay.io/fenicsproject/stable:latest
docker: Error response from daemon: create $(PWD): "$(PWD)" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path.
See 'docker run --help'.
C:\Users\neuma>docker run -ti -v $(PWD): C:/Users/neuma/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.
C:\Users\neuma>docker run -ti -v $(PWD): C:/fenics quay.io/fenicsproject/stable:latest
docker: invalid reference format.
See 'docker run --help'.

(I did create the fenics directories in the corresponding paths).

What happens if you run the command I suggested from power shell?

Your line was always the first I did try out (using power shell or terminal). So the first line of the quoted code of my last post was showing the results of runing the command you suggested.

What about

docker run -ti -v "C:\Users\neuma\fenics":/home/shared quay.io/fenicsproject/stable:latest
1 Like