No module named 'dolfin' on mac

Hello everybody,
I am trying to install fenics on my mac (m1 processor) I have come to activate fenicsproject but when I try to run the first simulation (demo_poisson.py) I get the following error message:

Traceback (most recent call last):
  File "demo_poisson.py", line 79, in <module>
    from dolfin import *
ModuleNotFoundError: No module named 'dolfin'

Where is the problem? What do you suggest me to do?

Please add a more detailed description of how you installed fenics on your computer, adding the list of commands you ran to install fenics.
If you found the instructions on a web page, please add the link for reference (for instance https://fenicsproject.org/download/archive/), and which of the paths here you followed.
Please also report the output of pip3 list

I tried to install fenics with the FEniCS on Anaconda procedure (described in the link indicated):

conda create -n fenicsproject -c conda-forge fenics
source activate fenicsproject

Next I ran the command:
conda activate fenicsproject and lastly, after downloading "demo_poisson.py from https://fenicsproject.org/olddocs/dolfin/latest/python/installation.html#quick-start I tried to run it simply with command: python demo_poisson.py

The output of pip3 list is:

Package         Version
--------------- -------------
fenics-dijitso  2019.2.0.dev0
fenics-ffc      2019.2.0.dev0
fenics-fiat     2019.2.0.dev0
fenics-ufl      2021.2.0.dev0
mpmath          1.2.1
numpy           1.22.2
pandas          1.4.1
pip             21.3.1
pycairo         1.20.1
pydicom         2.2.2
PyGObject       3.42.0
python-dateutil 2.8.2
pytz            2021.3
scipy           1.8.0
setuptools      60.5.0
six             1.16.0
sympy           1.9
wheel           0.37.1
```

Im suprised by the outputted version of the fenics dependencies, as they are not in the conda-forge https://anaconda.org/conda-forge/fenics/labels as far as Im aware.

Could you post the output of running:

conda create -n fenicsproject -c conda-forge fenics
WARNING: A conda environment already exists at '/Applications/anaconda3/envs/fenicsproject'
Remove existing environment (y/[n])? y

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Applications/anaconda3/envs/fenicsproject

  added / updated specs:
    - fenics


The following NEW packages will be INSTALLED:

  boost-cpp          conda-forge/osx-64::boost-cpp-1.74.0-hdbf7018_7
  bzip2              conda-forge/osx-64::bzip2-1.0.8-h0d85af4_4
  c-ares             conda-forge/osx-64::c-ares-1.18.1-h0d85af4_0
  ca-certificates    conda-forge/osx-64::ca-certificates-2021.10.8-h033912b_0
  cmake              conda-forge/osx-64::cmake-3.22.2-h4d639be_0
  eigen              conda-forge/osx-64::eigen-3.4.0-h940c156_0
  expat              conda-forge/osx-64::expat-2.4.6-h96cf925_0
  fenics             conda-forge/osx-64::fenics-2019.1.0-py39h6e9494a_26
  fenics-dijitso     conda-forge/osx-64::fenics-dijitso-2019.1.0-py39h6e9494a_26
  fenics-dolfin      conda-forge/osx-64::fenics-dolfin-2019.1.0-py39h1caa1a8_26
  fenics-ffc         conda-forge/osx-64::fenics-ffc-2019.1.0-py39h6e9494a_26
  fenics-fiat        conda-forge/osx-64::fenics-fiat-2019.1.0-py39h6e9494a_26
  fenics-libdolfin   conda-forge/osx-64::fenics-libdolfin-2019.1.0-h0741ba5_26
  fenics-ufl         conda-forge/osx-64::fenics-ufl-2019.1.0-py39h6e9494a_26
  fftw               conda-forge/osx-64::fftw-3.3.10-mpi_mpich_he67630e_2
  gmp                conda-forge/osx-64::gmp-6.2.1-h2e338ed_0
  gmpy2              conda-forge/osx-64::gmpy2-2.1.2-py39hab8a6df_0
  hdf5               conda-forge/osx-64::hdf5-1.10.6-mpi_mpich_h8c5dddf_1013
  hypre              conda-forge/osx-64::hypre-2.23.0-mpi_mpich_hfb0abaf_0
  icu                conda-forge/osx-64::icu-69.1-he49afe7_0
  krb5               conda-forge/osx-64::krb5-1.19.2-hcfbf3a7_3
  libblas            conda-forge/osx-64::libblas-3.9.0-13_osx64_openblas
  libcblas           conda-forge/osx-64::libcblas-3.9.0-13_osx64_openblas
  libcurl            conda-forge/osx-64::libcurl-7.81.0-hf45b732_0
  libcxx             conda-forge/osx-64::libcxx-12.0.1-habf9029_1
  libedit            conda-forge/osx-64::libedit-3.1.20191231-h0678c8f_2
  libev              conda-forge/osx-64::libev-4.33-haf1e3a3_1
  libffi             conda-forge/osx-64::libffi-3.4.2-h0d85af4_5
  libgfortran        conda-forge/osx-64::libgfortran-5.0.0-9_3_0_h6c81a4c_23
  libgfortran5       conda-forge/osx-64::libgfortran5-9.3.0-h6c81a4c_23
  libiconv           conda-forge/osx-64::libiconv-1.16-haf1e3a3_0
  liblapack          conda-forge/osx-64::liblapack-3.9.0-13_osx64_openblas
  libnghttp2         conda-forge/osx-64::libnghttp2-1.47.0-h942079c_0
  libopenblas        conda-forge/osx-64::libopenblas-0.3.18-openmp_h3351f45_0
  libssh2            conda-forge/osx-64::libssh2-1.10.0-h52ee1ee_2
  libuv              conda-forge/osx-64::libuv-1.43.0-h0d85af4_0
  libzlib            conda-forge/osx-64::libzlib-1.2.11-h9173be1_1013
  llvm-openmp        conda-forge/osx-64::llvm-openmp-13.0.1-hda6cdc1_0
  lz4-c              conda-forge/osx-64::lz4-c-1.9.3-he49afe7_1
  metis              conda-forge/osx-64::metis-5.1.0-h2e338ed_1006
  mpc                conda-forge/osx-64::mpc-1.2.1-hbb51d92_0
  mpfr               conda-forge/osx-64::mpfr-4.1.0-h0f52abe_1
  mpi                conda-forge/osx-64::mpi-1.0-mpich
  mpi4py             conda-forge/osx-64::mpi4py-3.1.3-py39ha81d895_0
  mpich              conda-forge/osx-64::mpich-3.4.3-hd33e60e_100
  mpmath             conda-forge/noarch::mpmath-1.2.1-pyhd8ed1ab_0
  mumps-include      conda-forge/osx-64::mumps-include-5.2.1-h694c41f_10
  mumps-mpi          conda-forge/osx-64::mumps-mpi-5.2.1-hae6d205_10
  ncurses            conda-forge/osx-64::ncurses-6.3-he49afe7_0
  numpy              conda-forge/osx-64::numpy-1.22.2-py39h9d9ce41_0
  openssl            conda-forge/osx-64::openssl-1.1.1l-h0d85af4_0
  parmetis           conda-forge/osx-64::parmetis-4.0.3-hb7fa8f8_1005
  petsc              conda-forge/osx-64::petsc-3.16.1-real_hecba10c_101
  petsc4py           conda-forge/osx-64::petsc4py-3.16.1-real_hba9dac2_100
  pip                conda-forge/noarch::pip-22.0.3-pyhd8ed1ab_0
  pkg-config         conda-forge/osx-64::pkg-config-0.29.2-h31203cd_1008
  pkgconfig          conda-forge/osx-64::pkgconfig-1.5.5-py39h6e9494a_1
  ptscotch           conda-forge/osx-64::ptscotch-6.0.9-h5077668_1
  pybind11           pkgs/main/osx-64::pybind11-2.8.1-py39haf03e11_0
  python             conda-forge/osx-64::python-3.9.10-h1dd9edd_2_cpython
  python_abi         conda-forge/osx-64::python_abi-3.9-2_cp39
  readline           conda-forge/osx-64::readline-8.1-h05e3726_0
  rhash              conda-forge/osx-64::rhash-1.4.1-h35c211d_0
  scalapack          conda-forge/osx-64::scalapack-2.1.0-hb62163f_0
  scotch             conda-forge/osx-64::scotch-6.0.9-h9f43b6f_1
  setuptools         conda-forge/osx-64::setuptools-60.9.3-py39h6e9494a_0
  six                conda-forge/noarch::six-1.16.0-pyh6c4a22f_0
  slepc              conda-forge/osx-64::slepc-3.16.1-real_ha131d38_101
  slepc4py           conda-forge/osx-64::slepc4py-3.16.1-real_h776a5bf_100
  sqlite             conda-forge/osx-64::sqlite-3.37.0-h23a322b_0
  suitesparse        conda-forge/osx-64::suitesparse-5.10.1-h7aff33d_1
  superlu            conda-forge/osx-64::superlu-5.2.2-h621599f_0
  superlu_dist       conda-forge/osx-64::superlu_dist-7.2.0-h4bb6bf2_0
  sympy              conda-forge/osx-64::sympy-1.9-py39h6e9494a_1
  tbb                conda-forge/osx-64::tbb-2021.5.0-h940c156_0
  tk                 conda-forge/osx-64::tk-8.6.12-h5dbffcc_0
  tzdata             conda-forge/noarch::tzdata-2021e-he74cb21_0
  wheel              conda-forge/noarch::wheel-0.37.1-pyhd8ed1ab_0
  xz                 conda-forge/osx-64::xz-5.2.5-haf1e3a3_1
  yaml               conda-forge/osx-64::yaml-0.2.5-h0d85af4_2
  zlib               conda-forge/osx-64::zlib-1.2.11-h9173be1_1013
  zstd               conda-forge/osx-64::zstd-1.5.2-h582d3a0_0


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate fenicsproject
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Here it installs the 2019.1.0 version of dolfin, while your pip3 list points to the 2019.2.0.dev0 version of dolfin.
Could you now post the output of

conda activate fenicsproject

followed by

pip3 list

and

which pip3
(base) Mac:~ lorenzomarta$ conda activate fenicsproject
(fenicsproject) Mac:~ lorenzomarta$ pip3 list
Package         Version
--------------- -------------
fenics-dijitso  2019.2.0.dev0
fenics-ffc      2019.2.0.dev0
fenics-fiat     2019.2.0.dev0
fenics-ufl      2021.2.0.dev0
mpmath          1.2.1
numpy           1.22.2
pandas          1.4.1
pip             21.3.1
pycairo         1.20.1
pydicom         2.2.2
PyGObject       3.42.0
python-dateutil 2.8.2
pytz            2021.3
scipy           1.8.0
setuptools      60.5.0
six             1.16.0
sympy           1.9
wheel           0.37.1
WARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/opt/homebrew/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip' command.
(fenicsproject) Mac:~ lorenzomarta$ which pip3
/opt/homebrew/bin/pip3

i just updated pip to version 22.0.3. The output is the same except for package pip version 22.0.3

If you call which pip3 outside the conda environment, what path do you then get?

To me it looks like the PYTHONPATH is not updated correctly when activating the conda environment.

As I do not have a mac, and rarely uses conda, I can’t give much further assistance. Maybe @dparsons or @jackhale knows more about this than I do.

I have found a solution. I’m not sure what the basic computer theory behind it is but it seems to work.
It is necessary, before activating fenicsproject, to deactivate (base) which “dominates” the other environment.
So just run the following commands:

conda deactivates
conda activate fenicsproject

Check the $PATH env variable. Prior to activating the environment, you should have conda in your path:

(base) root@e0730920c745:/fenics# which python3
/root/anaconda3/bin/python3
(base) root@e0730920c745:/fenics# echo $PYTHONPATH
/usr/local/dolfinx-real/lib/python3.8/dist-packages:/usr/local/lib:

while after activating the environment, the path should point to the envirionment you have created, as shown below:

(base) root@e0730920c745:/fenics# conda activate fenicsproject
(fenicsproject) root@e0730920c745:/fenics# echo $PYTHONPATH
/usr/local/dolfinx-real/lib/python3.8/dist-packages:/usr/local/lib:
(fenicsproject) root@e0730920c745:/fenics# echo $PATH
/root/anaconda3/envs/fenicsproject/bin:/root/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
(fenicsproject) root@e0730920c745:/fenics# which python3
/root/anaconda3/envs/fenicsproject/bin/python3

Similarly the python3 should be the one in /root/anaconda3/envs/fenicsproject.