Getting errors when trying to install dolfin

I’m trying to install the fenics package using WSL. I used the mamba package manager and did

mamba install fenics

inside a virtual environment I created with mamba to get the fenics package. However, I got this error when trying to run my script:

  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/jit/jit.py", line 15, in <module>
    if pkgconfig.exists("dolfin"):
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/pkgconfig/pkgconfig.py", line 93, in _wrapper
    raise EnvironmentError("pkg-config probably not installed: %r" % e)
OSError: pkg-config probably not installed: FileNotFoundError(2, 'No such file or directory')

ChatGPT told me to resolve this by running the command

sudo apt-get install pkg-config

and this fixed it but then I got this new error:

  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/jit/jit.py", line 18, in <module>
    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.

Again, ChatGPT told me to solve this with

sudo apt-get install python3-dolfin

and this worked and now my script works. I’m just not sure why these steps were required as I thought dolfin comes with the fenics installation when using conda/mamba. Also, these sudo commands don’t install the packages within my virtual environment so I’m not sure whether this will pose any problems later on. Can someone verify I did the installation correctly?

Note: The script was run within Pycharm Pro.

This installs something globally on your system.

This also installs globally and doesn’t use mamba.

You asked an AI to solve your problem, and it didn’t give you a suitable solution.

Without all the details about what OS you are using, what commands you used to install mamba and then in turn fenics, it is hard to give you any guidance.

@dokken
I’m on Windows 10 and using the latest version of Ubuntu to run WSL. I used

curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" > "miniconda3.sh"
bash miniconda3.sh

to install conda and

curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-$(uname)-$(uname -m).sh"
bash Mambaforge-$(uname)-$(uname -m).sh

to install mamba and then created a virtual environment with mamba create -n nameofmyenv python=3.9.
I used mamba install fenics to install fenics. I set my python interpreter on pycharm pro to home\User\mambaforge\envs\nameofmyenv\bin\python39. However, when I try running the demo_poisson.py file, I get the first error in the post above OSError: pkg-config probably not installed: FileNotFoundError(2, 'No such file or directory'). What was wrong with the solution I used of installing pkg-config globally? If I try installing it with mamba install, it just says all requested packages already installed.

There are many things to debug here, following the steps you have already performed.
I would start with

  1. Activate the conda environment from a terminal.
  2. Try runningwhich python3. Check that the output matches the conda env path.
  3. check if `python3 -c “import dolfin” works
  4. if it works, trying returning the demo and report the full output and input.
    4b. If it does not work, try conda install fenics, and report the full input/output, not just the one-line error message.

@dokken

Thanks for your reply.

  1. This gives home\User\mambaforge\envs\nameofmyenv\bin\python3 instead of the home\User\mambaforge\envs\nameofmyenv\bin\python39 that I have my interpreter set on. However, I just changed the interpreter to this path and it returned the same error. Does it matter which one I select?
  2. Edit: Ignore previous info. I entered this command and it did nothing, just returned the prompt again.
  3. This is the full message I get when I run demo_poisson.py with the interpreter now set on python3 instead of python39.
/home/User/mambaforge/envs/nameofmyenv/bin/python3 /mnt/h/User/Downloads/demo_poisson.py 
Traceback (most recent call last):
  File "/home/adeel/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/pkgconfig/pkgconfig.py", line 91, in _wrapper
    return func(*args, **kwargs)
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/pkgconfig/pkgconfig.py", line 125, in exists
    return call(cmd) == 0
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/subprocess.py", line 349, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'pkg-config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/h/User/Downloads/demo_poisson.py", line 79, in <module>
    from dolfin import *
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/__init__.py", line 142, in <module>
    from .fem.assembling import (assemble, assemble_system, assemble_multimesh,
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/fem/assembling.py", line 34, in <module>
    from dolfin.fem.form import Form
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/fem/form.py", line 12, in <module>
    from dolfin.jit.jit import dolfin_pc, ffc_jit
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/dolfin/jit/jit.py", line 15, in <module>
    if pkgconfig.exists("dolfin"):
  File "/home/User/mambaforge/envs/nameofmyenv/lib/python3.9/site-packages/pkgconfig/pkgconfig.py", line 93, in _wrapper
    raise EnvironmentError("pkg-config probably not installed: %r" % e)
OSError: pkg-config probably not installed: FileNotFoundError(2, 'No such file or directory')

Process finished with exit code 1

Let me know if you need further information.

I would try:
mamba install -c conda-forge pkgconfig

@dokken Same as before, says all requested packages already installed. I believe mamba already uses the conda-forge channel by default. Is the method I used of using sudo to install pkgconfig not the correct way to go about it?