{"componentChunkName":"component---src-templates-blog-post-js","path":"/2018/07/07/pyenv-matplotlib-high-sierra","result":{"data":{"markdownRemark":{"id":"b8dc24ac-9fbb-55a5-9f1f-b903ca1528c0","html":"<h1>Pyenv and matplotlib on MacOS High Sierra</h1>\n<p>Have you seen this error when trying to use <code class=\"language-text\">matplotlib</code> (or <code class=\"language-text\">ggplot</code> for that matter...)?</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">from matplotlib.backends import _macosx\nRuntimeError: 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 &#39;python&#39; with &#39;pythonw&#39;. See &#39;Working with Matplotlib on OSX&#39; in the Matplotlib FAQ for more information.</code></pre></div>\n<h2>Frameworks is it? I'll give ye frameworks...</h2>\n<p>The combination of Pyenv and virtualenv is the only sensible approach to Python development (for me). Imagine the deep sighs followed by gut-wrenching sobs when I was innocently trying to plot some data and saw the above error. The first thing to do is remove your virtualenv and delete the version of <code class=\"language-text\">pyenv</code> managed Python you were using (make sure you <code class=\"language-text\">pip freeze</code> before hand!)</p>\n<p>It is possible to provide environment variables that are specific to the command being run simply by prefixing the command. In this case we want to install Python 3.x as a framework.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token assign-left variable\">PYTHON_CONFIGURE_OPTS</span><span class=\"token operator\">=</span><span class=\"token string\">\"--enable-framework\"</span> pyenv <span class=\"token function\">install</span> <span class=\"token number\">3.6</span>.5</code></pre></div>\n<p>Sadly, I discovered, as I was nodding, almost napping - upon my keyboard a tapping - that this will complain; zlib is not installed, then openssl is problematic and on and on.</p>\n<p>Apparently this is an issue with MacOS High Sierra not referencing various libraries, nor compiling openssl properly. There is a solution involving <code class=\"language-text\">homebrew</code> (assuming you have installed pyenv etc through homebrew) and setting various compiler flags that facilitate compiling <code class=\"language-text\">openssl</code> properly:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token assign-left variable\">PYTHON_CONFIGURE_OPTS</span><span class=\"token operator\">=</span><span class=\"token string\">\"--enable-framework\"</span> <span class=\"token assign-left variable\">CFLAGS</span><span class=\"token operator\">=</span><span class=\"token string\">\"-I<span class=\"token variable\"><span class=\"token variable\">$(</span>brew --prefix openssl<span class=\"token variable\">)</span></span>/include\"</span> <span class=\"token assign-left variable\">LDFLAGS</span><span class=\"token operator\">=</span><span class=\"token string\">\"-L<span class=\"token variable\"><span class=\"token variable\">$(</span>brew --prefix openssl<span class=\"token variable\">)</span></span>/lib\"</span> pyenv <span class=\"token function\">install</span> <span class=\"token number\">3.6</span>.5</code></pre></div>\n<p>This will take a few minutes to complete but hopefully you should then be able to output <code class=\"language-text\">matplotlib</code> charts to your hearts content</p>","frontmatter":{"date":"7th July, 2018","title":"Pyenv and matplotlib on MacOS High Sierra","description":null,"image":null},"fields":{"readingTime":{"text":"2 min read"}}},"allMarkdownRemark":{"group":[{"fieldValue":"abstractsyntaxtrees","totalCount":2,"nodes":[{"id":"8c5ae399-e3f1-5b63-87e7-1133f665f611","excerpt":"Part One - an overview This is part one of a series of articles about abstract syntax trees and their use in javascript…","fields":{"slug":"2019/02/07/ast-fun-and-profit"},"frontmatter":{"title":"Abstract Syntax Trees for fun and profit"}},{"id":"832cc22e-4dfb-5b8e-a44f-72d25ada99bc","excerpt":"My previous article on abstract syntax trees ran through a quick, but relatively broad, overview of syntax trees and how…","fields":{"slug":"2019/04/28/ast-selectors-rule"},"frontmatter":{"title":"AST selectors rule"}}]},{"fieldValue":"browsersynth","totalCount":2,"nodes":[{"id":"1da8cc5b-c760-5f3d-bf0a-e80e28b9433b","excerpt":"Many modern browsers allow you to access your audio and MIDI hardware - that means you can build synths! As a quick…","fields":{"slug":"2018/03/10/midi-audio-api"},"frontmatter":{"title":"MIDI API"}},{"id":"466e67e4-29f7-5794-a860-4da05e83387c","excerpt":"As you may want to create synths using the synth 'framework' I'm working on, I'll run through some of the basics of…","fields":{"slug":"2018/04/08/synth-basics"},"frontmatter":{"title":"Synth Basics"}}]},{"fieldValue":"testing","totalCount":1,"nodes":[{"id":"2e6c64b7-8f2d-54f9-adde-e4008ea368b1","excerpt":"As a group, developers are a funny lot. We have a rosy view of ourselves. We like to think we are proud of our craft. We…","fields":{"slug":"2019/03/04/code-coverage"},"frontmatter":{"title":"Code coverage rocks"}}]}]}},"pageContext":{"slug":"2018/07/07/pyenv-matplotlib-high-sierra"}}}