Solve the error of running Matplotlib on Tensorflow on Mac OSX

If you are running Matplotlib on Mac to draw some figures, you might in counter some problem such as:

“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 Working with Matplotlib in a virtual enviroment see ‘Working with Matplotlib in Virtual environments’ in the Matplotlib FAQ”

The solution can be found here:

https://matplotlib.org/faq/osx_framework.html

In my case, I am using Python provided in Anaconda. Every is all right when I am just running Matplotlib to plot some figures of my python files. I simply use pythonw instead of python to run python files.

Below is the command I used to run a “test.py” file on terminal.

$ pythonw test.py

However, when I am running Matplotlib of some python files on tensorflow, pythonw has no module called tensorflow. Since using python could successfully run tensorflow, using pythonw would fail. The solution that I found is to write some codes in the matplotlibrc file under the path “/.matplotlib/matplotlibrc”.

$ vim ~/.matplotlib/matplotlibrc

Inside this file, write code

$ backend: TkAgg

That’s it! Save the changed and run again the python file again, and this time you use python instead of pythonw.

$ python test.py

Cheers!

Ting-Hao Chen
Aug 24, 2017

Advertisements

Install numexpr on Mac OSX

You might need to install “brew” first, so you could install numexpr in the following way.

How to install “brew”? Check out here:
https://chentinghao.wordpress.com/2016/02/23/install-opencv-on-your-mac-osx-with-python/#more-259

Step 1. Open your terminal on Mac and type the codes below:

$ sudo pip install numexpr

Then type your password to authorize the installation. After installation, you will see something like this:

Successfully installed numexpr-2.5

Ting-Hao Chen
Mar 14, 2016

Install OpenCV on your Mac OSX with Python

In this post, I am going to tell you how to install OpenCV on your Mac OSX, so that you can import cv in your python code. In my case, I’ll be installing OpenCV 2.4.12 and running python 2.7 on my Mac OSX. The version of OpenCV will keep updating, so in the following procedure you might need to change the version number. Otherwise, there might be some errors installing.

Let’s get started.

Continue reading “Install OpenCV on your Mac OSX with Python”

Install pims_nd2 on your Mac OSX

Before installing pims_nd2, make sure you already installed “pip” on your mac. You could learn how to install “pip” here:

https://chentinghao.wordpress.com/2016/02/15/install-pip-on-mac-osx/

I followed the instructions below. If you still have problem, make sure to check it out!

https://pypi.python.org/pypi/pims_nd2

Let me tell you how to install pims_nd2 step by step, so let’s get started!

Continue reading “Install pims_nd2 on your Mac OSX”

Install pip on Mac OSX

Hi there,

In this post, I will tell you step by step how to install “pip” on Mac OSX Yosemite with Python support. Basically, I follow the instructions of the website shown below:

https://pip.pypa.io/en/stable/installing/

In case you still have problem following the procedure in this post, make sure to take a look at the website which might help you solve the problem.

Let’s get started!

Continue reading “Install pip on Mac OSX”