Hi,
If I install a python package that has FEniCS as a dependency, I run into ImportError: cannot import name 'sub_forms_by_domain'
(see also Ubuntu 18.04 - ImportError: cannot import name 'sub_forms_by_domain'). The following Dockerfile hopefully explains what I mean and helps reproducing the error:
# same behavior with ubuntu:20.04
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -y -qq software-properties-common git
RUN add-apt-repository ppa:fenics-packages/fenics
RUN apt-get install -y --no-install-recommends fenics
RUN python3 -c "from fenics import *"
RUN apt-get install -y python3-pip
WORKDIR my_dummy_package
RUN echo "from setuptools import setup" >> setup.py
RUN echo "setup(name='dummy-package', install_requires=['fenics'])" >> setup.py
RUN pip3 install .
#RUN pip3 uninstall -y fenics-ufl # uncommenting this line fixes the problem
RUN python3 -c "from fenics import *" # breaks with ImportError
From the log it is visible that installing the dummy-package
also installs fenics-ufl
:
Step 12/13 : RUN pip3 install .
---> Running in ...
Processing /my_dummy_package
Collecting fenics (from dummy-package==0.0.0)
Downloading https://files.pythonhosted.org/packages/d0/de/3c458c4cb1264e81cb96deab36eca65a4875e310755c59869649ef7769ef/fenics-2019.1.0-py3-none-any.whl
Collecting fenics-ufl<2019.2,>=2019.1.0 (from fenics->dummy-package==0.0.0)
Downloading https://files.pythonhosted.org/packages/59/cd/e102c234b8be3bcff5395c555182caf2d1662e24e0417b0005e5f05ec33c/fenics_ufl-2019.1.0-py3-none-any.whl (282kB)
Collecting fenics-fiat<2019.2,>=2019.1.0 (from fenics->dummy-package==0.0.0)
Downloading https://files.pythonhosted.org/packages/05/54/e463570ef224ca199c2baf0b77f10b8de44ce9b40374c0fc229d108e6c26/fenics_fiat-2019.1.0-py3-none-any.whl (112kB)
Collecting fenics-dijitso<2019.2,>=2019.1.0 (from fenics->dummy-package==0.0.0)
Downloading https://files.pythonhosted.org/packages/f2/62/c061cb9f8f5547915804cdf8046fe2989c5b7317445fb1246ac77a9bad7f/fenics_dijitso-2019.1.0-py3-none-any.whl (46kB)
Collecting fenics-ffc<2019.2,>=2019.1.0 (from fenics->dummy-package==0.0.0)
Downloading https://files.pythonhosted.org/packages/74/b6/0c3743a5b9fecaf3b7fe7b0c6526e7c635bd1bb6f9bc4a177bababc79131/fenics_ffc-2019.1.0.post0-py3-none-any.whl (362kB)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from fenics-ufl<2019.2,>=2019.1.0->fenics->dummy-package==0.0.0)
Requirement already satisfied: sympy in /usr/lib/python3/dist-packages (from fenics-fiat<2019.2,>=2019.1.0->fenics->dummy-package==0.0.0)
Installing collected packages: fenics-ufl, fenics-fiat, fenics-dijitso, fenics-ffc, fenics, dummy-package
Found existing installation: fenics-ufl 2019.2.0.dev0
Not uninstalling fenics-ufl at /usr/lib/python3/dist-packages, outside environment /usr
Found existing installation: fenics-fiat 2019.2.0.dev0
Not uninstalling fenics-fiat at /usr/lib/python3/dist-packages, outside environment /usr
Found existing installation: fenics-dijitso 2019.2.0.dev0
Not uninstalling fenics-dijitso at /usr/lib/python3/dist-packages, outside environment /usr
Found existing installation: fenics-ffc 2019.2.0.dev0
Not uninstalling fenics-ffc at /usr/lib/python3/dist-packages, outside environment /usr
Running setup.py install for dummy-package: started
Running setup.py install for dummy-package: finished with status 'done'
Successfully installed dummy-package-0.0.0 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
Why does pip3 install .
also install fenics-ufl
? Should this requirement not already be satisfied when installing FEniCS using apt
above?
I was wondering whether the dependency on fenics
(install_requires=['fenics']
) might be formulated wrongly or whether I’m using pip3
in the wrong way. Not uninstalling ... at ..., outside environment /usr
seems to be considered a bug/unexpected behavior https://github.com/pypa/pip/issues/3352. But maybe there is also something one can improve on the FEniCS side or as the maintainer of dummy-package
in order to make life for users easier?
Uninstalling fenics-ufl
is no big deal, but in the end it looks to me like a work-around.
Thanks for any help!
Benjamin