c3sr/scope_plot

scope_plot doesn't work inside a pipenv venv on macOS

Closed this issue · 3 comments

Version / Platform Info

  • ScopePlot Version: 120b613
  • Known Operating System(s) affected__:
    • Windows
    • Linux
    • Mac OS

Expected Behavior

cd scope_plot
pyenv install 3.6.6
pyenv local 3.6.6
pipenv --python 3.6
pipenv shell
pip install -e .
scope_plot -h

This should print the help message.

Actual Behavior

$ scope_plot -h
Traceback (most recent call last):
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/bin/scope_plot", line 11, in <module>
    load_entry_point('scope-plot', 'console_scripts', 'scope_plot')()
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2707, in load_entry_point
    return ep.load()
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2325, in load
    return self.resolve()
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2331, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Users/carl.pearson/repos/scope_plot/scope_plot/cli.py", line 14, in <module>
    from scope_plot import backend
  File "/Users/carl.pearson/repos/scope_plot/scope_plot/backend.py", line 3, in <module>
    import scope_plot.backends.matplotlib as matplotlib_backend
  File "/Users/carl.pearson/repos/scope_plot/scope_plot/backends/matplotlib.py", line 9, in <module>
    import matplotlib.pyplot as plt
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/Users/carl.pearson/.local/share/virtualenvs/scope_plot-jkXQDA0f/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
    from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

Perhaps

env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.6.6

or

import matplotlib
matplotlib.use("agg")

Didn't end up getting the PYTHON_CONFIGURE_OPTS to work, so for now in d7aaf16 we just do

import sys
if sys.platform == "darwin":
    import matplotlib
    matplotlib.use("TkAgg")