glumpy icon indicating copy to clipboard operation
glumpy copied to clipboard

IPython on OSX -- RuntimeError: Freetype library not found

Open p-i- opened this issue 7 years ago • 21 comments

I'm trying to get this code working.

It says it can't find glumpy.

sudo pip install glumpy

Now it says it can't find OpenGL.

sudo pip install pyopengl

Now it's says it can't find freetype. But pip fails to locate that lib. Luckily anaconda works:

conda install freetype

But even though the installation completed successfully, my IPython notebook cell keeps spitting out "RuntimeError: Freetype library not found"

I'm not sure what to do next.

Notebook is here

https://github.com/glumpy/glumpy/blob/master/glumpy/ext/freetype/init.py#L32 digging ^ this is where it's failing. So anaconda must have installed freetype somewhere weird.

p-i- avatar Sep 11 '16 12:09 p-i-

You also need the freetype library but on OSX it should be installed. Do you use homebrew ? If yes, then you can brew install freetype

rougier avatar Sep 11 '16 13:09 rougier

I solved this by finding out where Anaconda had put it and doing:

sudo cp anaconda/lib/libfree* /usr/local/lib

This probably means my iPython notebook is using system Python rather than Anaconda Python, but at least it works.

p-i- avatar Sep 11 '16 13:09 p-i-

PS Wow I just noticed you specialise in computational neuroscience. I'm currently trying to use your lib to visualise a neuron's weight Matrix for a backpropagating neural network.

PPS Now I've got that one figured out I'm hitting http://pipad.org/tmp/backend_fail.html -- is there something obvious I'm missing?

p-i- avatar Sep 11 '16 13:09 p-i-

You cannot use glumpy from within the Jupyter notebook, you'll have to use regular python shell.

How large is your matrix ?

rougier avatar Sep 11 '16 18:09 rougier

I was thinking of visualizing the entire network in real time: e.g. a 16x16 grid of input neurons, 50 hidden-layer neurons (each with a 16x16 weight-matrix), 10 classifiers (each with 100 inputs).

p-i- avatar Sep 12 '16 08:09 p-i-

Do you know how to organize your display (how many images to be show , size and where) ?

rougier avatar Sep 12 '16 09:09 rougier

I don't really need visualisation for my current task. But I think it is worth investigating real-time visualisation from IPython Notebooks with an eye to future tasks... It could be very useful in debugging NNs that fail to converge for example. I'm familiar with coding GL ES2 (vertex and fragment shaders).

p-i- avatar Sep 12 '16 09:09 p-i-

Ok. If you look at the gloo-image.py example, this might do what you want.

rougier avatar Sep 12 '16 10:09 rougier

I tried sudo cp anaconda/lib/libfree* /usr/local/lib and I tried conda install freetype then I tried brew install freetype

And I am sure that the FREETYPE is right inside both /usr/local/lib and /usr/local/Cellar/freetype/2.7.1/lib

Yet I still got the error of RuntimeError: Freetype library not found

File "/Users/cycleuser/.pyenv/versions/anaconda3-4.0.0/lib/python3.5/site-packages/glumpy/ext/freetype/__init__.py", line 49, in <module> raise RuntimeError('Freetype library not found') RuntimeError: Freetype library not found

I tried python2.7.12, 3.5.2, 3.5.3, 3.6.0, from system, anaconda or brew. The OS is macOS 10.12 I use 21 hours to install each of them and try and fail on each one.

So is there any way that I can be saved?

cycleuser avatar Mar 07 '17 02:03 cycleuser

Can you try (from a python shell):

>>> import ctypes.util
>>> ctypes.util.find_library("freetype")

rougier avatar Mar 07 '17 06:03 rougier

>>> import ctypes.util
>>> ctypes.util.find_library("freetype")

Nothing shows up , seem like the brew link freetype failed. I have already copied these files below to /usr/local/lib/

libfreetype.6.dylib
libfreetype.a
libfreetype.dylib
libfreetype.la

cycleuser avatar Mar 07 '17 08:03 cycleuser

Weird, on OSX (sierra), I got:

'/usr/locaL/lib/libfreetype.dylib'

rougier avatar Mar 07 '17 09:03 rougier

@rougier
Thanks a lot! Maybe it's caused by the bashrc?

Could you please send me a copy of your bashrc ?

I got the same files in the same locations, and the /usr/local/lib is also added to the PATH , that is really strange~

cycleuser avatar Mar 07 '17 10:03 cycleuser

@rougier Thanks a lot!

I uninstall the Brew and delete all the files generated by Brew. Then I install a brand new brew and everything is ok .

import ctypes.util
ctypes.util.find_library("freetype")

shows:

'libfreetype.dylib'

in iPython with Python 3.5.2.

cycleuser avatar Mar 07 '17 16:03 cycleuser

Cool! Are glumpy examples running ok now ?

rougier avatar Mar 07 '17 16:03 rougier

Gonna test it again.

Seem like the lib location is wrong some how:

export DYLD_FALLBACK_LIBRARY_PATH="/usr/lib"
export DYLD_FALLBACK_LIBRARY_PATH="/usr/local/lib:DYLD_FALLBACK_LIBRARY_PATH"
export PATH="/usr/local/lib:$PATH"

then it also works

Gonna test it later

cycleuser avatar Mar 07 '17 16:03 cycleuser

while I am using:

python earth.py

it gives me this:

  File "earth.py", line 9, in <module>
    from glumpy.transforms import Arcball, Viewport, Position
ImportError: cannot import name 'Arcball'

There may be some other problems and I will explore later~

cycleuser avatar Mar 07 '17 16:03 cycleuser

@rougier

Same problem as last year. I just change Arcball to Trackball and it works.

cycleuser avatar Mar 08 '17 03:03 cycleuser

I met the same problem after I updated the Mac OS X, so this problem arises depending on the version of the OS X, and I managed to find a solution, just changing line 40 in https://github.com/glumpy/glumpy/blob/master/glumpy/ext/freetype/init.py to: __dll__ = ctypes.CDLL('/opt/X11/lib/libfreetype.6.dylib'), or any path of libfreetype.6.dylib.

biaojiang avatar Aug 28 '17 07:08 biaojiang

I'm not sure if I should open a new issue for this, but ctypes.util.find_library does not properly locate Homebrew-installed "freetype" in my M1 Mac.

It is probably due to the fact that Homebrew does not write to /usr/local/lib anymore on M1 macs; the path to libfreetype.dylib on my Mac is /opt/homebrew/lib/libfreetype.dylib.

Is there a better way than to manually changing the line

FT_Library_filename = ctypes.util.find_library('freetype')

to

FT_Library_filename = "/opt/homebrew/lib/libfreetype.dylib"

in ext/freetype/__init__.py?

Zeta611 avatar Apr 30 '22 13:04 Zeta611

Thanks for the report. This should be reproted to ctypes I think. There is not much I can do.

rougier avatar May 02 '22 08:05 rougier