Dolfin import problems with Python 3.4

732 views
Skip to first unread message

Timo Betcke

unread,
Jan 23, 2016, 11:10:41 AM1/23/16
to fenics-support
Hi,

I am installing Fenics on a Centos 7 computer using Python 3.4. Everything compiles and installs as expected. But when I want to import dolfin I get the following error.

In [1]: import dolfin
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-7d9b2153bc0b> in <module>()
----> 1 import dolfin

/home/betcke/apps/python/lib64/python3.4/site-packages/dolfin/__init__.py in <module>()
     14
     15 # Import names from the compiled cpp modules
---> 16 from . import cpp
     17 from dolfin.cpp import *
     18 from dolfin.cpp import __version__, __swigversion__, __pythonversion__

/home/betcke/apps/python/lib64/python3.4/site-packages/dolfin/cpp/__init__.py in <module>()
     40
     41     # Import the module
---> 42     exec("from . import %s" % module_name)
     43     module = globals()[module_name]
     44

/home/betcke/apps/python/lib64/python3.4/site-packages/dolfin/cpp/__init__.py in <module>()

/home/betcke/apps/python/lib64/python3.4/site-packages/dolfin/cpp/la.py in <module>()
    142     return _la.has_slepc4py()
    143 has_slepc4py = _la.has_slepc4py
--> 144 import common
    145 class LinearAlgebraObject(common.Variable):
    146     """

ImportError: No module named 'common'

I can fix this import by changing 'import dolfin' to 'from . import dolfin' Similarly, several other imports in modules in the 'cpp' subdirectory need to be adapted.
Is this workaround still necessary for installation with Python 3 or did I miss a compiler option during the installation?

Best wishes

Timo


Timo Betcke

unread,
Jan 23, 2016, 1:04:07 PM1/23/16
to fenics-support
Short corrections. I certainly meant changing "import common" to "from . import common".

Timo

Johannes Ring

unread,
Jan 25, 2016, 3:27:59 AM1/25/16
to Timo Betcke, fenics-support
Are you using the stable version or the development version? On the
py3 buildbot, which builds the development version, I can see that it
is 'from . import common' in la.py, not 'import common'.

Johannes
> --
> You received this message because you are subscribed to the Google Groups
> "fenics-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to fenics-suppor...@googlegroups.com.
> To post to this group, send email to fenics-...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fenics-support/db5817f1-c928-4fb2-9d73-898d9c911f41%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Johannes Ring

unread,
Jan 25, 2016, 5:21:09 AM1/25/16
to Timo Betcke, fenics-support
[please keep fenics-support in cc]

I just tried building FEniCS 1.6 with the johannr/fenics-py3 branch in
hashstack [1] and I see the same problem. Your workaround is therefore
still needed with version 1.6, while the development version works
fine without it.

[1] https://github.com/hashdist/hashstack/tree/johannr/fenics-py3

Johannes

On Mon, Jan 25, 2016 at 11:01 AM, Timo Betcke <timo....@gmail.com> wrote:
> Hi Johannes,
>
> I am using the stable 1.6 version which I have patched manually.
> Best wishes
>
> Timo
> --
> Dr. Timo Betcke
> Reader in Mathematics
> University College London
> Department of Mathematics
> E-Mail: t.be...@ucl.ac.uk
> Tel.: +44 (0) 20-3108-4068
> Fax.: +44 (0) 20-7383-5519
Reply all
Reply to author
Forward
0 new messages