This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to find dolfin after installing FEniCS through conda?

0 votes

I've installed FEniCS using conda (anaconda2) as recommended in the link below.

conda install -c conda-forge fenics
https://fenics.readthedocs.io/en/latest/

I've noticed that dolfin and mshr are not included in the new packages to be installed. Furthermore after running this and running ipython the dolfin module can't be found.

Is dolfin installed in this process? If so where can I find it/make it known to ipython?

asked Apr 28, 2017 by aldenpack FEniCS User (1,450 points)
edited Apr 28, 2017 by aldenpack

1 Answer

0 votes
 
Best answer

Try installing mshr and ipython from the conda-forge channel as well:

conda install -c conda-forge fenics mshr ipython

A better approach might be to create a separate environment like this:

conda create -n fenicsproject -c conda-forge python=3.6 fenics mshr ipython

You can then activate this environment by running:

source activate fenicsproject
answered Apr 28, 2017 by johannr FEniCS Expert (17,350 points)
selected Jul 14, 2017 by aldenpack

Maybe I am trying to import dolfin incorrectly. After following your approach when I run 'from dolfin import *' i get the following error...

In [1]: from dolfin import *

TypeError Traceback (most recent call last)
in ()
----> 1 from dolfin import *

/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/init.pyc in ()
38
39 # Imports from pure Python modules
---> 40 from dolfin.common import *
41 from dolfin.functions import *
42 from dolfin.compilemodules import *

/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/common/init.py in ()
1 # -- coding: utf-8 --
2 """The common module of dolfin"""
----> 3 from dolfin.common import globalparameters
4 from dolfin.common import constants
5 from dolfin.common import plotting

/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/common/globalparameters.py in ()
26 # Add form compiler parameters to global parameter set
27 if not parameters.has_parameter_set("form_compiler"):
---> 28 form_compiler_parameters = Parameters("form_compiler", **default_jit_parameters())
29 parameters.add(form_compiler_parameters)

/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/cpp/common.pyc in new_Parameter_init(self, *args, **kwargs)
2815 raise TypeError("expected a range tuple of size 2 for 'str' values and 3 for scalars")
2816 else:
-> 2817 self.add(key,value)
2818
2819 Parameters.__init__ = __new_Parameter_init__

/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/cpp/common.pyc in add(self, args)
2541 self._add_bool(
args)
2542 else:
-> 2543 self._add(*args)
2544
2545 def parse(self,argv=None):

TypeError: in method 'Parameters__add', argument 3 of type 'std::string'

What does this mean? What am I doing wrong?

Dolfin does not appear in the list produced by running pip.get_installed_distributions(). Should it be there? That's what initially made me think it's not installed correctly. I'm also running python 2.7, would that cause any errors?

No, dolfin is not in pip.get_installed_distributions(). Since you are using Python 2.7, you should of course do this instead:

conda create -n fenicsproject -c conda-forge python=2.7 fenics mshr ipython

Try also these two commands:

python -c "import dolfin;print(dolfin.__file__)"
ipython -c "import dolfin;print(dolfin.__file__)"

I still get the same error. The following line causes the following error.

python -c "import dolfin;print(dolfin.__file__)"

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/__init__.py", line 40, in <module>
        from dolfin.common import *
      File "/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/common/__init__.py", line 3, in <module>
        from dolfin.common import globalparameters
      File "/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/common/globalparameters.py", line 28, in <module>
        form_compiler_parameters = Parameters("form_compiler", **default_jit_parameters())
      File "/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/cpp/common.py", line 2817, in __new_Parameter_init__
        self.add(key,value)
      File "/fslhome/apack/anaconda2/envs/fenicsproject/lib/python2.7/site-packages/dolfin/cpp/common.py", line 2543, in add
        self._add(*args)
    TypeError: in method 'Parameters__add', argument 3 of type 'std::string'
    Aborted

Any Ideas?

Not sure. You can try sending a message to the FEniCS support mailing list.

An administrator on the machine I am using got this to work with python3. I was using python2.7 before but I can switch to python3. The following command was needed to have ipython locate the dolfin module.

export PYTHONPATH=/zapps/conda/conda3/envs/fenicsproject/lib/python3.6/site-packages
...