Fenics from Conda doesn't import

Howdy,

So I’ve downloaded fenics several times in the past, with no issue. Today when I downloaded fenics using conda I get :

import dolfin
Traceback (most recent call last):
File “”, line 1, in
File “/anaconda3/envs/optcontrol/lib/python3.7/site-packages/dolfin/init.py”, line 142, in
from .fem.assembling import (assemble, assemble_system, assemble_multimesh,
File “/anaconda3/envs/optcontrol/lib/python3.7/site-packages/dolfin/fem/assembling.py”, line 34, in
from dolfin.fem.form import Form
File “/anaconda3/envs/optcontrol/lib/python3.7/site-packages/dolfin/fem/form.py”, line 12, in
from dolfin.jit.jit import dolfin_pc, ffc_jit
File “/anaconda3/envs/optcontrol/lib/python3.7/site-packages/dolfin/jit/jit.py”, line 18, in
raise RuntimeError(“Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set.”)
RuntimeError: Could not find DOLFIN pkg-config file. Please make sure appropriate paths are set.

I have python 3.7.6 currently. Any suggestions how I can resolve this issue?

Thank you.

This might be of help: RuntimeError: Could not find DOLFIN pkg-config file

I unfortunately don’t use J notebooks. I’ve always called my fenics programs via python command. I’m not sure what the issue is because I’ve downloaded fenics several times previous on different machines and I haven’t ran into this issue. Any other tips @dokken?

you can check if the environment is loaded by typing in the python terminal

#test if environment fenics is activated
import os
print(os.environ[‘PATH’])

and check if the environment fenics is present in the path:
you should get something like

/anaconda3/envs/fenicsproject/bin:/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin

of course fenicsproject would be replaced by the name you gave to the environment where you did “conda install fenics”

did you “conda activate” the environment from the terminal or from the anaconda navigator GUI (which is apparently bugged) see the post RuntimeError: Could not find DOLFIN pkg-config file

1 Like

Hi, Ryan, did you solve this problem? I happen to run into a similar issue.

Hi George,

I’ve found that if I make a python virtual environment with anaconda, and then install fenics (with the conda-forge command) via anaconda into that virtual environment then things work great. I just run my programs from this environment. I think the issue is that if you don’t have a closed virtual environment, there might be a chance that you pip installed something in the past that comes in conflict with anaconda.

Hi, Ryan,
I tried the following but it is still not working,

  1. conda create -n fenicsproject
  2. conda activate fenicsproject
  3. conda install -c conda-forge python=3.8.1 fenics
    Is this what you did?
    Thank you!

I would do

  1. conda create -n fenicsproject python=3.7
  2. conda activate fenicsproject
  3. conda install -c conda-forge fenics

when I do the " 1. conda create -n fenicsproject python=3.7" , I get the error:
PackagesNotFoundError: The following packages are not available from current channels:

  • python=3.7

Can you help me with this?

Conda no longer supports Python 3.7, ref: Managing Python — conda 23.5.1.dev35 documentation

So, what is your suggestion to install fenics on conda? consider creating a new environment. What should I do to install fenics on conda on mac if I want to use it on J notebook?
Thank you so much for your help.

You should use a newer version of Python in your conda env

Can you help me which version I should install?
You mean, if I install the newer version of python, I can install fenics with " conda install -c conda-forge fenics" ?

I updated the python to the 3.10 version but I still get error installing fenics.
PackagesNotFoundError: The following packages are not available from current channels:

  • fenics

What kind of system are you on?
The fenics conda package is at Fenics :: Anaconda.org and has a large variety of supported platforms and versions, see Files :: Anaconda.org

It may be worth sharing the output of conda info. The fenics packages on conda don’t have builds for arm macs, for example.

If you do have an arm Mac, you can create an environment using intel packages (they will work, just not as fast) with:

conda create --override-channels -c conda-forge/osx-64 -c conda-forge/noarch -n fenics fenics

I have Pro M1 system which is arm. I used the command you suggested and activated the fenics environment and here is the conda info:
active environment : fenics
active env location : /opt/anaconda3/envs/fenics
shell level : 2
user config file : /Users/eli/.condarc
populated config files : /Users/eli/.condarc
conda version : 22.9.0
conda-build version : 3.22.0
python version : 3.9.13.final.0
virtual packages : __osx=12.5=0
__unix=0=0
__archspec=1=arm64
base environment : /opt/anaconda3 (writable)
conda av data dir : /opt/anaconda3/etc/conda
conda av metadata url : None
channel URLs : conda-forge/osx-arm64
conda-forge/noarch
main/osx-arm64
main/noarch
r/osx-arm64
r/noarch
package cache : /opt/anaconda3/pkgs
/Users/eli/.conda/pkgs
envs directories : /opt/anaconda3/envs
/Users/eli/.conda/envs
platform : osx-arm64
user-agent : conda/22.9.0 requests/2.28.1 CPython/3.9.13 Darwin/21.6.0 OSX/12.5
UID:GID : 501:20
netrc file : None
offline mode : False

Now what should I do to install jupyter at this environment? I installed it with conda install jupyter but it does not open with this.
Thank you so much for your help.

I tried all commands on Files :: Anaconda.org and none of them worked. my system is M1 Pro.

Same command, adding any number of packages:

conda create --override-channels -c conda-forge/osx-64 -c conda-forge/noarch -n fenics fenics jupyterlab matplotlib …

Or to add packages to an existing env, change create to install.

To use this env, you’ll want to run

conda activate fenics after which you can run JupyterLab etc.

2 Likes

Thank you so much! It worked!