NameError - cannot use any Mantid specific functions

I can’t seem to use any Mantid specific functions within the script editor in MantidPlot on Windows 7

I have set the python path as suggested here: http://www.mantidproject.org/File:MantidInPython.png

I’ve tried the following imports:

from mantidplot import *
from mantid import *
from mantid.simpleapi import *

If I try to import mantid from a python shell in the command prompt, I get the following:

>>>from mantid.simpleapi import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\MantidInstall\bin\mantid\__init__.py", line 73, in <modu
    import mantid.kernel as kernel
  File "c:\MantidInstall\bin\mantid\kernel\__init__.py", line 14, i
    from ._kernel import *
ImportError: DLL load failed: %1 is not a valid Win32 application.

I’m not sure what’s going wrong here.

Actually, it turns out most functions are accessible but some (such as mtdHelp() and setWorkingDirectory() ) are not.

In the script editor within Mantidplot most of those import are included automatically, you only need those if you are using pure python outside of Mantidplot.

Yes, I thought this also so I tried no import statements at all as well and the functions still raise a NameError.

Hi Tom,

Those functions are actually no longer available and existed in version 1 of our python package a few years ago. Have you found a reference to them somewhere?

Their equivalent is just standard Python functions:

  • mtdHelp()help()
  • setWorkspaceDirectory()os.chdir() (this will require import os at the top of the file)

Martyn

Ah I see, that makes sense.

Yes, here’s the reference: http://www.mantidproject.org/Learning_Python

Cheers Martyn,

Tom

Thanks for pointing me to that. It’s page that has missed being updated. We’ll sort it out.

I have added a redirect to Introduction To Python - Mantid Project as this is our much more up to date training course along with the other courses that are linked from the main https://www.mantidproject.org/ under the quickstart section.

1 Like