xraypy / xraylarch

Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging, and more.
https://xraypy.github.io/xraylarch
Other
138 stars 68 forks source link

wx import issue in both bash and conda installs: solved by installing wxpython #249

Closed charlesll closed 2 years ago

charlesll commented 6 years ago

Hi,

I tried installing Larch using miniconda as well as the bash script on Linux x86-64. In both case I end with an error message related to wx when trying to import larch:

>>> import larch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/__init__.py", line 28, in <module>
    from .shell import shell
  File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/shell.py", line 10, in <module>
    from .interpreter import Interpreter
  File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/interpreter.py", line 18, in <module>
    from . import builtins
  File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/builtins.py", line 22, in <module>
    from . import fitting
  File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/fitting/__init__.py", line 6, in <module>
    import wx
  File "/home/charles/xraylarch/lib/python3.6/site-packages/wx/__init__.py", line 12, in <module>
    __version__ = wx.__version__.VERSION_STRING
AttributeError: module 'wx' has no attribute '__version__'

This issue is solved by installing wxpython with conda.

Should wxpython be added as a dependency?

newville commented 6 years ago

Hi Charles,

On Wed, Sep 5, 2018 at 2:32 AM Charles Le Losq notifications@github.com wrote:

Hi,

I tried installing Larch using miniconda as well as the bash script on Linux x86-64.

Sorry for the trouble. Could you be more specific about what steps you took?

Do you mean that you installed one environment with miniconda, and then another with "the bash script" or was that one install where you first installed miniconda and then ran "the bash script" on the same environment? Also, which bash script are you referring to?

In both case I end with an error message related to wx when trying to

import larch:

import larch Traceback (most recent call last): File "", line 1, in File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/init.py", line 28, in from .shell import shell File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/shell.py", line 10, in from .interpreter import Interpreter File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/interpreter.py", line 18, in from . import builtins File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/builtins.py", line 22, in from . import fitting File "/home/charles/xraylarch/lib/python3.6/site-packages/larch/fitting/init.py", line 6, in import wx File "/home/charles/xraylarch/lib/python3.6/site-packages/wx/init.py", line 12, in version = wx.version.VERSION_STRING AttributeError: module 'wx' has no attribute 'version'

This implies to me that wx was imported but that it did not have a __version__. That's odd. I would ask what version that was, but it seems that will be unknowable ;).

Anyway, that seems like a broken-ish wx to me. I'd like to understand how that happened, so details on the install steps would be helpful.

This issue is solved by installing wxpython with conda.

Should wxpython be added as a dependency?

Maybe... We do try to make wxPython optional, and in fact the error you got comes from code where we test for ImportError, but not AttributeError which is why I think the wx install is broken. We initially wanted to make Larch be able to run on a small-ish, non-graphical system and so without wxPython. I think that is a fine goal, even if we are not meeting it 100%.

OTOH, if using a modern conda environment (as of this year or so), I have no problem requiring that wxPython 4 is required as this is now supported for all Anaconda Python versions. And the conda package for xraylarch does depend on wxpython, and and the single-install bash-script ( xraylarch-0.9.40-Linux-x86_64.sh) should definitely install the wxpython-4.0.1 conda package.

Anyway, that's just to say that I'd like to understand what happened in more detail. Thanks!

--Matt

newville commented 6 years ago

@charlesll as a follow-up, I found this:

  ~> bash  ~/Downloads/Miniconda3-latest-Linux-x86_64.sh
  ~> export PATH=/home/newville/miniconda3/bin:$PATH
  ~> conda install -c gsecars xraylarch

gave me a complete and working system:

  ~> which xas_viewer
  ~/miniconda3/bin/xas_viewer
  ~> xas_viewer

runs fine. Do you get different results?

charlesll commented 6 years ago

Hi,

Yes of course. First, this problem was raised when trying to install on Manjaro Linux (rolling release, Arch-based, kernel 4.18).

All in all, it seems related to the version of wxpython that is installed during Larch install, which may not be compatible with my setup?

In all cases, thanks for the hard work on this package, it looks great!

newville commented 6 years ago

@charlesll Thanks very much for the details. It still seems sort of odd to me, but we can definitely deprecate using the wxpython 4.0.0a3 package, which seems like it may be sufficient to avoid the problem.

Larch (especially xas_viewer) definitely needs lmfit 0.9.11, but that too should be included. I'm (again!) not sure why the install isn't picking up the latest package.

charlesll commented 6 years ago

No problem! Yes I don't really understand what happened...

For lmfit on Mac OS, it is even stranger. The larch install proceed with downloading and installing 0.9.11... But when I did pip install --upgrade lmfit, it turns out that 0.9.7 was active and upgraded to 0.9.11 ... I can't understand why... I had no version of lmfit installed on this computer prior to installing larch. In all cases, problem is solved by upgrading to 0.9.11 with pip

On another note: are you interested in Jupyter Notebook examples of the use of Larch? If yes, I could push some to the examples folder at the occasion.

Cheers, Charles.

newville commented 6 years ago

@charlesll

On another note: are you interested in Jupyter Notebook examples of the use of Larch? If yes, I could push some to the examples folder at the occasion.

Yes, that would be very nice. Having a Larch kernel for Jupyter would also be kinda cool for many uses. It looks like it is probably not too hard, but I have not gone very far into that idea.

fluxmap commented 5 years ago

Hi @charlesll, Hi @newville

@newville Thanks for your efforts putting this package together. Seems reasonable to add my issue here (?). I have tried installing larch on a Mac running OS Mojave (10.14.2) with mixed results.

Using the MacOS installer I am able to successfully run the XAS_veiwer and Larch_GUI via the desktop shortcuts created during install. There may be some strangeness there but I didn't pay close attention and haven't probed to deeply. I was able to undertake some LCF so at first pass looks good.

When I tried to call larch from the terminal however I get the following error -

larch Traceback (most recent call last): File "/Users/SAJ/anaconda2/bin/larch", line 61, in import larch File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/init.py", line 28, in from .shell import shell File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/shell.py", line 10, in from .interpreter import Interpreter File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/interpreter.py", line 18, in from . import builtins File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/builtins.py", line 22, in from . import fitting File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/fitting/init.py", line 26, in from lmfit import (Parameter, Parameters, Minimizer, conf_interval, ImportError: cannot import name ufloat

As I would like to use larch within a Jupyter notebook I abandoned this approach and tried using larch within my anaconda python 3.6 environment. I have been unsuccessful, receiving a seemingly related but distinct error when trying to import larch in a JupyterLab notebook or Jupyter QtConsole session -

ImportError Traceback (most recent call last)

in ----> 1 import larch ~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/__init__.py in 26 from .site_config import show_site_config 27 from .symboltable import Group, SymbolTable, isgroup ---> 28 from .shell import shell 29 from .inputText import InputText 30 from .utils import Closure, fixName, nativepath, get_homedir ~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/shell.py in 8 9 from .symboltable import SymbolTable ---> 10 from .interpreter import Interpreter 11 from .site_config import history_file, show_site_config 12 from .version import __version__, __date__, make_banner ~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/interpreter.py in 16 import six 17 ---> 18 from . import builtins 19 from . import site_config 20 from .symboltable import SymbolTable, Group, isgroup ~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/builtins.py in 20 from . import inputText 21 from . import site_config ---> 22 from . import fitting 23 from .larchlib import parse_group_args, LarchExceptionHolder 24 from .symboltable import isgroup ~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/fitting/__init__.py in 24 25 import lmfit ---> 26 from lmfit import (Parameter, Parameters, Minimizer, conf_interval, 27 ci_report, conf_interval2d, ufloat, correlated_values) 28 ImportError: cannot import name 'ufloat' This program needs access to the screen. Please run with a Framework build of python, and only when you are logged in on the main display of your Mac. Note: Same error message whether I am working off the laptop screen or external monitor. Any suggestions on how to resolve one or both of these issues would be welcomed gladly. Cheers, Simon
newville commented 5 years ago

@fluxmap

@newville https://github.com/newville Thanks for your efforts putting

this package together. Seems reasonable to add my issue here (?). I have tried installing larch on a Mac running OS Mojave (10.14.2) with mixed results.

Using the MacOS installer I am able to successfully run the XAS_veiwer and Larch_GUI via the desktop shortcuts created during install. There may be some strangeness there but I didn't pay close attention and haven't probed to deeply. I was able to undertake some LCF so at first pass looks good.

When I tried to call larch from the terminal however I get the following error -

larch Traceback (most recent call last): File "/Users/SAJ/anaconda2/bin/larch", line 61, in import larch File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/init.py", line 28, in from .shell import shell File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/shell.py", line 10, in from .interpreter import Interpreter File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/interpreter.py", line 18, in from . import builtins File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/builtins.py", line 22, in from . import fitting File "/Users/SAJ/anaconda2/lib/python2.7/site-packages/larch/fitting/ init.py", line 26, in from lmfit import (Parameter, Parameters, Minimizer, conf_interval, ImportError: cannot import name ufloat

This is probably because the installer created an Anaconda Python 3 environment in $HOME/xraylarch, and the desktop icons point to that folder.

The error you're getting from $HOME/anaconda2 environment looks to be a mismatch (that is completely my fault) between lmfit 0.9.12 and larch 0.9.40 (the problem is solved in the github master version of xraylarch, which I hope to release as 0.9.41 in a few days). If you make sure you're using $HOME/anaconda2/bin/python, doing

 ~>  python -m pip install lmfit==0.9.11

should solve that problem.

As I would like to use larch within a Jupyter notebook I abandoned this

approach and tried using larch within my anaconda python 3.6 environment. I have been unsuccessful, receiving a seemingly related but distinct error when trying to import larch in a JupyterLab notebook or Jupyter QtConsole session -

Yes, this would be nice. I believe this can work OK on Linux and Windows, but that there is a real challenge to make this work well with Anaconda Python on MacOS. This challenge is essentially a problem with Anaconda Python on MacOS and wxPython. I'll skip some of the details here, but I think it may be a problem for using larch with jupyter on MacOS. It might not be a small problem, but I agree that it is worth trying to fix.

ImportError Traceback (most recent call last)

in ----> 1 import larch

~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/init.py in 26 from .site_config import show_site_config 27 from .symboltable import Group, SymbolTable, isgroup ---> 28 from .shell import shell 29 from .inputText import InputText 30 from .utils import Closure, fixName, nativepath, get_homedir

~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/shell.py in 8 9 from .symboltable import SymbolTable ---> 10 from .interpreter import Interpreter 11 from .site_config import history_file, show_site_config 12 from .version import version, date, make_banner

~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/interpreter.py in 16 import six 17 ---> 18 from . import builtins 19 from . import site_config 20 from .symboltable import SymbolTable, Group, isgroup

~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/builtins.py in 20 from . import inputText 21 from . import site_config ---> 22 from . import fitting 23 from .larchlib import parse_group_args, LarchExceptionHolder 24 from .symboltable import isgroup

~/anaconda2/envs/python_3/lib/python3.6/site-packages/larch/fitting/init.py in 24 25 import lmfit ---> 26 from lmfit import (Parameter, Parameters, Minimizer, conf_interval, 27 ci_report, conf_interval2d, ufloat, correlated_values) 28

ImportError: cannot import name 'ufloat' This program needs access to the screen. Please run with a Framework build of python, and only when you are logged in on the main display of your Mac.

Note: Same error message whether I am working off the laptop screen or external monitor. Any suggestions on how to resolve one or both of these issues would be welcomed gladly.

This is the combination of the two different problems. The 'ufloat' is due to using lmfit > 0.9.11 and larch = 0.9.40 release. This will be fixed soon, but you can also revert to lmfit=0.9.11 for now. The "framework" message when tyring to use jupyter on MacOS is a bigger problem.

fluxmap commented 5 years ago

Boom! Your suggested fix worked. Larch now launches from the terminal. Thanks for the background on the "framework" problem, I run a windows VM (incidentally this is where I keep Demeter) so will give the notebook approach a go in that OS. Appreciate your help, much obliged.

Cheers, Simon

maurov commented 5 years ago

@newville, I think this issue can be closed, as wxpython is now in requirements.txt, plus the AttributeError is catched in #258.