Calling Mantid from Python

I am running OSX 10.10.5 and MantidPlot 3.4. I have python installed and I added the following path to the PYTHONPATH:

/Applications/MantidPlot.app/Contents/MacOS/

When I try to import the Mantid module into python (2.7.9) I get the following error:

>>> from mantid.simpleapi import *
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

Then Python crashes.
Any idea what could be the problem?

Thanks,
Sándor

Hi Sandor
to import into ipython i use this method rather than appending the pythonpath

import sys
sys.path.append(r’/Applications/MantidPlot.app/Contents/MacOS’)
from mantid.simpleapi import *

i then get the message:
FrameworkManager-[Notice] Welcome to Mantid 3.5.0
FrameworkManager-[Notice] Please cite: http://dx.doi.org/10.1016/j.nima.2014.07.029 and this release: http://dx.doi.org/10.5286/Software/Mantid3.5
DownloadInstrument-[Notice] All instrument definitions up to date

let me know how this goes
all the best
Jon

Dear Jon,

Thank you for the quick answer! I get the same error message as before (after running your lines in python). Is there any debugging I could do to figure out what could be the problem? (the MantidPlot.app runs fine)

Thanks,
Sandor

Hi Sandor,
a couple of questions are you using the python 2.7 that is installed with osx and have you installed anything using brew or another mac package manager?
cheers
jon

I use python installed with brew, beside many other unrelated packages:

autoconf		hdf5			p7zip
automake		hicolor-icon-theme	pango
boost			icu4c			pixman
boost-python		intltool		pkg-config
brew-cask		jasper			poco147p1
cabextract		jpeg			pyqt
cairo			jsoncpp			python
cmake			libffi			python3
docbook			libgphoto2		qscintilla2
fontconfig		libicns			qt
freeimage		libmxml			qwt5
freetype		libpng			qwtplot3d
ftgl			libtiff			readline
gd			libtool			sane-backends
gdbm			libusb			sip
gettext			libusb-compat		sqlite
gl2ps			libxml2			szip
glib			little-cms2		unrar
gobject-introspection	makedepend		wine
gperftools		muparser		winetricks
gsl			nexusformat		xz
harfbuzz		oce0p16p1
hdf4			openssl

I also have a long list of python modules installed by pip:

alabaster (0.7.6)
appnope (0.1.0)
Babel (2.1.1)
backports.ssl-match-hostname (3.4.0.2)
BeautifulSoup (3.2.1)
certifi (2015.9.6.2)
decorator (4.0.4)
docutils (0.12)
funcsigs (0.4)
functools32 (3.2.3.post2)
gnureadline (6.3.3)
ipykernel (4.0.3)
ipython (4.0.0)
ipython-genutils (0.1.0)
ipywidgets (4.0.3)
Jinja2 (2.8)
jsonschema (2.5.1)
jupyter (1.0.0)
jupyter-client (4.0.0)
jupyter-console (4.0.2)
jupyter-core (4.0.6)
MarkupSafe (0.23)
matplotlib (1.4.3)
mistune (0.7.1)
mock (1.3.0)
nbconvert (4.0.0)
nbformat (4.0.0)
nose (1.3.7)
notebook (4.0.5)
numpy (1.9.3)
path.py (8.1.1)
pbr (1.8.0)
pexpect (3.3)
phonopy (1.9.6.2)
pickleshare (0.5)
pip (7.1.2)
psutil (3.2.2)
ptyprocess (0.5)
Pygments (2.0.2)
pyparsing (2.0.3)
python-dateutil (2.4.2)
pytz (2015.6)
PyYAML (3.11)
pyzmq (14.7.0)
qtconsole (4.0.1)
scipy (0.16.0)
setuptools (18.3.2)
simplegeneric (0.8.1)
six (1.9.0)
snowballstemmer (1.2.0)
Sphinx (1.3.1)
sphinx-bootstrap-theme (0.4.7)
sphinx-rtd-theme (0.1.9)
terminado (0.5)
tornado (4.2.1)
traitlets (4.0.0)
vboxapi (1.0)
wheel (0.26.0)

Cheers,
Sandor

Hi
so it turned out that i had the same issue when running a python shell & homebrew python 2.7 (normally i use ipython notebook linked to the osx system python2.7)
could you try importing the module using python at /usr/bin/python which points to the osx system python.

with brew installed the python that gets picked up is /usr/local/Cellar/python which gets a sym link in /usr/local/bin.
if you could check that things work with the system python first I’ll ask people who use brew more than me what to do
cheers
jon

Dear Jon,

thank you for the quick answer! Removing the brew python installation helped. Now I can import the mantid.simpleapi module.

Best,
Sandor