Skip to content

Commit 8c07c3c

Browse files
committed
Try and provide more comprehensive __init__ error message if import fails
1 parent 4742205 commit 8c07c3c

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

fidimag/__init__.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
1+
import os
2+
import sys
13
try:
24
from . import extensions
5+
from . import common
6+
from . import atomistic
7+
from . import micro
38
except ImportError as e:
4-
import os
59
cwd = os.getcwd()
610
FIDIMAG_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
711
os.chdir(FIDIMAG_DIR)
8-
print("Could not find fidimag extensions. Trying to build them now...")
12+
message = """
13+
Could not load the Fidimag extensions. This could be due to a few things:
14+
1) The extensions are not built (we'll try and build them now).
15+
2) FIDIMAG loads comon libraries dynamically. Currently, FIDIMAG requires
16+
* Sundials 2.6.2
17+
* FFTW 3.3.5
18+
If you are using Linux, you may be able to download these through a
19+
package manager such as apt or yum. However, convenience scripts
20+
are provided in the folder bin to install these locally.
21+
3) If you've run the scripts to install the dynamic libaries,
22+
you may still need to export the LD_LIBRARY_PATH environment
23+
variable. You can do this from the shell with:
24+
export LD_LIBRARY_PATH={}:$LD_LIBRARY_PATH
25+
"""
26+
print(message.format(FIDIMAG_DIR))
927
os.system("make build")
1028
print("Building extensions done.")
1129
os.chdir(cwd)
12-
from . import common
13-
from . import atomistic
14-
from . import micro
30+
try:
31+
from . import extensions
32+
from . import common
33+
from . import atomistic
34+
from . import micro
35+
except ImportError as e:
36+
raise ImportError("Loading the FIDIMAG extensions still didn't work."
37+
"\nTry the steps above!")
38+
39+
1540
from .gui import GUI
1641

1742
citation = common.citation

0 commit comments

Comments
 (0)