I’m trying to install FEniCS within Jupyter Labs (so I can import the package in my current notebooks by doing simply import fenics
), but I’m failing miserably. First I installed it through pip3 install fenics
as any other package, and in fact this is the output if I try to do it again:
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: fenics in /usr/local/lib/python3.9/site-packages (2019.1.0)
Requirement already satisfied: fenics-ufl<2019.2,>=2019.1.0 in /usr/local/lib/python3.9/site-packages (from fenics) (2019.1.0)
Requirement already satisfied: fenics-ffc<2019.2,>=2019.1.0 in /usr/local/lib/python3.9/site-packages (from fenics) (2019.1.0.post0)
Requirement already satisfied: fenics-dijitso<2019.2,>=2019.1.0 in /usr/local/lib/python3.9/site-packages (from fenics) (2019.1.0)
Requirement already satisfied: fenics-fiat<2019.2,>=2019.1.0 in /usr/local/lib/python3.9/site-packages (from fenics) (2019.1.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.9/site-packages (from fenics-dijitso<2019.2,>=2019.1.0->fenics) (1.22.4)
Requirement already satisfied: sympy in /usr/local/lib/python3.9/site-packages (from fenics-fiat<2019.2,>=2019.1.0->fenics) (1.10.1)
Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.9/site-packages (from sympy->fenics-fiat<2019.2,>=2019.1.0->fenics) (1.2.1)
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
WARNING: There was an error checking the latest version of pip.
So the package is already there. However, when I import fenics in my notebooks, I get
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import fenics
ModuleNotFoundError: No module named 'fenics'
I have also tried to follow the instructions in https://fenicsproject.org/qa/13194/how-to-use-fenics-in-jupyter-by-anaconda/, which was linked by many in the context of similar questions. I did conda create -n fenicsproject -c conda-forge python=3.5 jupyter fenics
, but when I then do source activate fenicsproject
I get source: no such file or directory: activate
. I tried instead conda activate fenicsproject
, and while the environment is active I still can't import the package into my notebook.
Does anyone know a set of magic steps to be able to use FEniCS within Jupyter Labs? In case it's relevant, I'm using MacOS Monterey 12.4 with conda 4.13.0 and python 3.5.5. Many thanks!
UPDATE:
With the following commands I was able to create a kernel for my new environment within Jupyter:
conda create -n fenicsproject -c conda-forge fenics
conda activate fenicsprojec
python -m ipykernel install --user --name fenicsproject --display-name "Python (FEniCS)"
Now, when I do import fenics
I get:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import fenics
File ~/opt/anaconda3/envs/fenicsproject/lib/python3.10/site-packages/fenics/__init__.py:7, in <module>
1 # -*- coding: utf-8 -*-
2 """Main module for FEniCS.
3
4 This module is identical with the main DOLFIN module.
5 """
----> 7 from dolfin import *
File ~/opt/anaconda3/envs/fenicsproject/lib/python3.10/site-packages/dolfin/__init__.py:142, in <module>
139 from .common.timer import Timer, timed
140 from .common.plotting import plot
--> 142 from .fem.assembling import (assemble, assemble_system, assemble_multimesh,
143 SystemAssembler, assemble_local)
144 from .fem.form import Form
145 from .fem.norms import norm, errornorm
File ~/opt/anaconda3/envs/fenicsproject/lib/python3.10/site-packages/dolfin/fem/assembling.py:34, in <module>
32 import ufl
33 import dolfin.cpp as cpp
---> 34 from dolfin.fem.form import Form
35 from dolfin import MPI
36 from dolfin.function.multimeshfunction import MultiMeshFunction
File ~/opt/anaconda3/envs/fenicsproject/lib/python3.10/site-packages/dolfin/fem/form.py:12, in <module>
10 import ufl
11 import dolfin.cpp as cpp
---> 12 from dolfin.jit.jit import dolfin_pc, ffc_jit
15 class Form(cpp.fem.Form):
16 def __init__(self, form, **kwargs):
17
18 # Check form argument
File ~/opt/anaconda3/envs/fenicsproject/lib/python3.10/site-packages/dolfin/jit/jit.py:18, in <module>
16 dolfin_pc = pkgconfig.parse("dolfin")
17 else:
---> 18 raise RuntimeError("Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set.")
21 # Copied over from site-packages
22 def mpi_jit_decorator(local_jit, *args, **kwargs):
RuntimeError: Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set.
UPDATE 2:
As a clarification based on this post, the previous error happens when I launch jupyter lab from the terminal.
In any case, the outcome of env
is the following:
__CFBundleIdentifier=com.apple.Terminal
TMPDIR=/var/folders/rv/zgc93kmn1b10ngl4t5813dm80000gn/T/
XPC_FLAGS=0x0
LaunchInstanceID=0825007E-A608-4580-8509-024A76F7768E
TERM=xterm-256color
DISPLAY=/private/tmp/com.apple.launchd.bSgkG6FpPC/org.xquartz:0
SECURITYSESSIONID=186a3
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.cAxEHmogW6/Listeners
XPC_SERVICE_NAME=0
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=445
TERM_SESSION_ID=53B396DE-4AF6-4F4C-8D39-D209C6E11CED
SHELL=/bin/zsh
HOME=/Users/myuser
LOGNAME=myuser
USER=myuser
PATH=/usr/local/bin:/Users/myuser/opt/anaconda3/envs/fenicsproject/bin:/Users/myuser/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
SHLVL=1
PWD=/Users/myuser
OLDPWD=/Users/myuser
CONDA_EXE=/Users/myuser/opt/anaconda3/bin/conda
_CE_M=
_CE_CONDA=
CONDA_PYTHON_EXE=/Users/myuser/opt/anaconda3/bin/python
CONDA_SHLVL=2
CONDA_PREFIX=/Users/myuser/opt/anaconda3/envs/fenicsproject
CONDA_DEFAULT_ENV=fenicsproject
CONDA_PROMPT_MODIFIER=(fenicsproject)
CONDA_PREFIX_1=/Users/myuser/opt/anaconda3
LC_CTYPE=UTF-8
_=/usr/bin/env
UPDATE 3 (SOLVED):
Contrary to the case in this post, I could make it work by launching Jupyter Lab within the fenicsproject env in the Anaconda Navigator.
source activate fenicsproject
withconda activate fenicproject
?env
to grab their values, then replicate them before launching the actual jupyter notebook. That sounds awful, but I lack better ideas. Fenics is awesome software, but a can of worms to actually run in my experience...env
in the original post.