spacetelescope / jwst_coronagraph_visibility

Visualize approximate pointing constraints for JWST coronagraphs.
https://github.com/spacetelescope/jwst_visibility/blob/master/docs/index.rst
BSD 3-Clause "New" or "Revised" License
8 stars 10 forks source link

ImportError: cannot import name 'NavigationToolbar2TkAgg' #20

Closed njcuk9999 closed 4 years ago

njcuk9999 commented 5 years ago

I cannot seem to run jwst-coronagraph-visibility-gui

I have tried installing on two (linux) systems using the astroconda

source activate astroconda
conda install jwst_coronagraph_visibility
jwst-coronagraph-visibility-gui &

Seems to be a problem importing NavigationToolbar2TkAgg from matplotlib.backends.backend_tkagg

version of matplotlib on both systems is 3.1.1, so I guess they have moved something since the last version of jwst_coronagraph_visibility was tested? (Note in matploliblib.backends.backend_tkagg they do have NavigationToolbar2Tk so maybe this is a simple fix?)

Full traceback is below:

>>   jwst-coronagraph-visibility-gui &
>>   Traceback (most recent call last):
  File "/scratch/bin/anaconda3/envs/astroconda/bin/jwst-coronagraph-visibility-gui", line 11, in <module>
    load_entry_point('jwst-coronagraph-visibility==0.3.0', 'gui_scripts', 'jwst-coronagraph-visibility-gui')()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/jwst_coronagraph_visibility/gui.py", line 29, in <module>
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
ImportError: cannot import name 'NavigationToolbar2TkAgg'

System information

System 1:

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

System 2

NAME="Ubuntu"
VERSION="18.04.3 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.3 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
joseph-long commented 5 years ago

Sadly it appears this has been unmaintained since I left STScI in August 2017. At the time I think @robelgeda was slated to take over, but that may have changed. @mperrin may also know who the current responsible party is.

If that change fixes it, please do submit a pull request!

mperrin commented 5 years ago

Attention @juliengirard, can you take a look at this issue please?

juliengirard commented 5 years ago

The way I managed to run it (python 3) ultimately is installing it with pip and not conda and forcing the installation of matplotlib 2.2.

That or using the precompiled version for Max OS.

njcuk9999 commented 5 years ago

This article may help: https://stackoverflow.com/questions/50330320/what-to-use-instead-of-navigationtoolbar2tkagg

In an easy world where NavigationToolbar2Tk works exactly the same as NavigationToolbar2TkAgg one could use a hack like the following:

try:
    from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
except ImportError:
    from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk as NavigationToolbar2TkAgg

that would support both older matplotlib versions and newer ones.

though it is never as easy and would depend on your usage of NavigationToolbar2TkAgg and how it differs from the new NavigationToolbar2Tk class

njcuk9999 commented 5 years ago

I decided to go ahead and test the above (https://github.com/spacetelescope/jwst_coronagraph_visibility/issues/20#issuecomment-537627672) on my machine, it does indeed work however there is an additional problem with FigureCanvasTkAgg as well

>>   Traceback (most recent call last):
  File "/scratch/bin/anaconda3/envs/astroconda/bin/jwst-coronagraph-visibility-gui", line 11, in <module>
    load_entry_point('jwst-coronagraph-visibility==0.3.0', 'gui_scripts', 'jwst-coronagraph-visibility-gui')()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/jwst_coronagraph_visibility/gui.py", line 1262, in run
    app = VisibilityCalculator()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/jwst_coronagraph_visibility/gui.py", line 335, in __init__
    self._build()
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/jwst_coronagraph_visibility/gui.py", line 402, in _build
    self._build_plots(self.plot_frame)
  File "/scratch/bin/anaconda3/envs/astroconda/lib/python3.6/site-packages/jwst_coronagraph_visibility/gui.py", line 779, in _build_plots
    self._canvas.show()
AttributeError: 'FigureCanvasTkAgg' object has no attribute 'show'

however this error I have seen before (see here: https://github.com/jarvisteach/appJar/issues/551) basically all you need to do is any places you use FigureCanvasTkAgg.show() (i.e. self._canvas.show() in gui.py) you need to add FigureCanvasTkAgg.draw() or self._canvas.draw() - however this would then make it incompatible with the older versions of matplotlib I imagine.

After this the gui tool works for me!

jbhagan commented 4 years ago

Thanks @njcuk9999, I implemented this fix.