Hi Sean,


On Wed, Aug 31, 2016 at 7:25 PM, Sean Fackler <swfackler@lbl.gov> wrote:
Hi Matt,

I do have wxPython installed and wxmplot. I use anaconda which should handle the obvious dependencies. Is there a list of known dependencies I should double check? 

 
if you're using Anaconda, the main dependencies are included in the basic setup, and doing "conda install -c newville xraylarch" should install everything else you need.  For reference (or if not using Anaconda), the hard dependencies are
   numpy, scipy, matplotlib, six, h5py, sqlalchemy, wxmplot, and wxutils.

The first six of those are common general purpose or scientific python tools (and may include compiled code or other dependencies that I don't list, but will get installed with them), and the last two are libraries I maintain (and are pure Python and add no other dependencies).

There are two optional packages: termcolor, and pyepics that may be used if available but are not required.  Termcolor is used by the command-line program to give color to the output text and pyepics is useful if you want to communicate with the Epics control system (which is used at some beamlines, especially in the US).

 
If you are using Anaconda python on OS X, there is a weirdness with wxPython that requires using "pythonw" instead of "python" as the interpreter (some Framework thing), but that "just" makes running larch from a command-line or script fail immediately with a message about not being able to draw to the screen.  The "larch_makeicons" makes mini-Apps that avoids this, and the next version will fix this even for the commandline programs.  

I am using Anaconda. I am a newb at Python. What do you mean I use pythonw as the interpreter? I am trying to script with larch and I don’t see any obvious places to replace python with pythonw. I tried installing a new Anaconda environment but didn’t see an obvious point at which to change the interpreter to pythonw.


For Anaconda on Mac OS X, using the standard "python" executable cannot draw to the screen with wxPython.   Instead, one must use
  ~> pythonw my_larch_using_script.py

instead of

  ~> python my_larch_using_script.py

You can also put "#!/usr/bin/env pythonw"  at the top of an executable script, not "#!/usr/bin/env python".    The installed programs "larch", "larch_gui", and so forth do this automatically on Mac OS X, and the Apps in the Larch folder built with "larch_makeicons" use the windowed interpreter.

For clarity, this irritating feature of "this program cannot draw to the window, it can only run from a terminal/console" was a common issue ten or more years ago on both Windows and Mac (Unices that used X11 solved this issue before anyone named Bush or Clinton was president),

I'm sure you're asking "why don't they just rename 'pythonw' 'python' and be done with it"?   I don't know why this doesn't work, but I can tell you from experience that it does not. Also, pythonw is not needed on Windows or Mac using "python.org python" or "macports python" (and probably not in "homebrew python").    I have complained to Continuum, as have others. 

 
Thanks for any further explanation. I get new_plot to work fine in the larch command line but I want to create new “modules” which I understand needs to be done by scripting larch in a python environment. 


There are two basic scenarios:

A) you want to write code that can be used inside Larch.   For this, writing plain Python and just import your code from within Larch should work fine.    If you want to write code that creates Larch Groups or builds on existing functionality, you can import larch and even its plugins.

B) you want to use Larch code from within plain Python.   For this, you sort of need to know where in the plugin hierarchy the functions you want to use are, but can then do something like:

     import larch
     from larch_plugins.xafs import autobk, pre_edge

To *use* many of the Larch plugin functions, it is necessary (or, at least, advised) to pass in an existing larch "session", using the '_larch' keyword argument to all (or at least the vast majority) of the plugin functions, like this:
   
      _session  = larch.Interpreter()
      outgroup = larch.Group()
      autobk(endata, mudata, rbkg=1.0, out=outgroup, _larch=_session)

Hope that's a good start!

--Matt