0

I am recently just learning Matplotlib from a book and am running into some issues installing.

I downloaded 1.4.2 source, changed line 961 setupext.py for freetype dependency then compiled, and installed in (env).

A pip freeze gives the basic requirements of (env).

matplotlib==1.4.2
mock==1.0.1
nose==1.3.4
numpy==1.9.1
pyparsing==2.0.3
python-dateutil==2.2
pytz==2014.9
six==1.8.0
wsgiref==0.1.2

I have a file called data_plot.py

#!/usr/bin/python
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import numpy as np
import matplotlib.pyplot as plt

# create x, randomly spaced between 0 to 20
x = np.linspace(0,20,10)

When running python data_plot.py it just seems to be stuck thinking.

stuck thinking

The console should spit out 10 random numbers from 0-20 correct? Did I compile it completely wrong? I uploaded all my files to github.

atrueresistance
  • 1,358
  • 5
  • 26
  • 48
  • I can reproduce this on OS X Mavericks (10.9.5). When I interrupt it with CTRL-C, the `matplotlib` import seems to be hanging when trying to call fontconfig's `fc-list`. – Lukas Graf Nov 25 '14 at 20:41
  • 1
    It seems this is an issue related to the fontCache. The solution provided in [this answer](http://stackoverflow.com/a/24982107/1599111) worked for me. – Lukas Graf Nov 25 '14 at 20:43
  • by the way np.linspace. Wont give you randomly spaced data. Instead it gives evenly spaced numbers over a specified interval (starting number, end number, number of intervals). Please see: http://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html – jonhurlock Nov 25 '14 at 22:30
  • @LukasGraf do you want to post that as an answer. – atrueresistance Nov 25 '14 at 23:29
  • possible duplicate of [import matplotlib.pyplot hangs](http://stackoverflow.com/questions/17490444/import-matplotlib-pyplot-hangs) – ivan_pozdeev Nov 26 '14 at 05:12
  • I have voted. need to more to mark as duplicate. – atrueresistance Nov 26 '14 at 05:26

1 Answers1

3

So I've just been teaching a course on using matplotlib with a bunch of other python pacakges (NumPy,SciPy,Scikit-learn), and have to install matplot lib on a few machines.

These are the installation instructions I have created to make sure you have matplotlib installed correctly for OS X Yosemite. I highly suggest doing all steps.

  1. Make sure you have Command Line tools installed, to do this type the following in the terminal:
    sudo xcode select --install
  2. Make sure you have GCC installed. These are the instructions to install GCC via home brew. The first line installs home brew, the second GCC.

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    sudo brew install gcc
  3. Make sure you have pip installed

    sudo easy_install pip
  4. Now install your packages, I would recommend getting NumPy and SciPy as well as matplotlib, if you don't already have them.

    sudo pip install -U numpy
    sudo pip install -U scipy
    sudo pip install -U matplotlib

Also I've just tried running the above code, and the output is as follows:

jonhurlock~$:python
Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> 
>>> # create x, randomly spaced between 0 to 20
... x = np.linspace(0,20,10)
>>> print x
[  0.           2.22222222   4.44444444   6.66666667   8.88888889
  11.11111111  13.33333333  15.55555556  17.77777778  20.        ]
>>> 
jonhurlock
  • 1,798
  • 1
  • 18
  • 28
  • 2
    Thanks for the directions, but installing matplotlib like that doesn't work. `* The following required packages can not be built: * freetype` That is why I ended up building from source. Finally got the intended output after running `fc-list` in `~/.matplotlib/` – atrueresistance Nov 25 '14 at 23:32