Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Andropov

macrumors 6502a
Original poster
May 3, 2012
746
990
Spain
I installed Python 3.6 and matplotlib (along with numpy, scipy, etc) through MacPorts on my iMac G4 but importing matplotlib.pyplot crashes python:

Code:
192:~ Raul$ python3
Python 3.6.5 (default, Mar 29 2018, 15:41:19)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
machdep: class is not implemented
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file
Abort trap
192:~ Raul$

Any idea why this happens?
Settings: iMac G4 1.25GHz, Mac OS X 10.5.8. Python 3.6.5. Matplotlib 2.1.1 installed through MacPorts with one dependency (qhull) installed with GCC 4.8 as 4.2 was blacklisted in MacPort's portfile.
 

Lastic

macrumors 6502a
Mar 19, 2016
879
757
North of the HellHole
I installed Python 3.6 and matplotlib (along with numpy, scipy, etc) through MacPorts on my iMac G4 but importing matplotlib.pyplot crashes python:

Code:
192:~ Raul$ python3
Python 3.6.5 (default, Mar 29 2018, 15:41:19)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
machdep: class is not implemented
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file
Abort trap
192:~ Raul$

Any idea why this happens?
Settings: iMac G4 1.25GHz, Mac OS X 10.5.8. Python 3.6.5. Matplotlib 2.1.1 installed through MacPorts with one dependency (qhull) installed with GCC 4.8 as 4.2 was blacklisted in MacPort's portfile.

Which version of MacPorts ?

I tried it on my G5 with MacPorts 2.4.2 but it pulled in way more depencies :

---> Computing dependencies for py36-matplotlib
The following dependencies will be installed:
cython_select
fftw-3
nosetests_select
py36-altgraph
py36-cython
py36-macholib
py36-modulegraph
py36-nose
py36-numpy
py36-parsing
py36-py2app
py36-pyobjc
py36-pyobjc-cocoa
py36-tornado
qhull

which in the end failed on

---> Building py36-pyobjc
Error: Failed to build py36-pyobjc: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pyobjc/py36-pyobjc/main.log for details.

cd /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_python_py-pyobjc/py36-pyobjc/work/pyobjc-core-3.0.4

sudo python setup.py install

running install
running bdist_egg
running egg_info
writing include/pyobjc-compat.h to Lib/pyobjc_core.egg-info/include/pyobjc-compat.h
writing include/pyobjc-api.h to Lib/pyobjc_core.egg-info/include/pyobjc-api.h
writing Lib/pyobjc_core.egg-info/PKG-INFO
writing dependency_links to Lib/pyobjc_core.egg-info/dependency_links.txt
writing namespace_packages to Lib/pyobjc_core.egg-info/namespace_packages.txt
writing top-level names to Lib/pyobjc_core.egg-info/top_level.txt

xcodebuild: Warning: SDK "macosx" cannot be located. Using project-defined SDK.

Error: A valid SDK was not specified on the command line for -sdk when used with -version.

So I'm wondering why your build succeeded but fails when you try to import the lib.
[doublepost=1522589605][/doublepost]I also tried with Macports 2.4.2 on my G4 Powerbook 12" but there it fails on qhull even when setting my GCC compiler to p-gcc49.
 

Lastic

macrumors 6502a
Mar 19, 2016
879
757
North of the HellHole
I installed Python 3.6 and matplotlib (along with numpy, scipy, etc) through MacPorts on my iMac G4 but importing matplotlib.pyplot crashes python:

Code:
192:~ Raul$ python3
Python 3.6.5 (default, Mar 29 2018, 15:41:19)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
machdep: class is not implemented
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file
Abort trap
192:~ Raul$

Any idea why this happens?
Settings: iMac G4 1.25GHz, Mac OS X 10.5.8. Python 3.6.5. Matplotlib 2.1.1 installed through MacPorts with one dependency (qhull) installed with GCC 4.8 as 4.2 was blacklisted in MacPort's portfile.

So what worked for me on my G5 is installing Matplotlib via pip install

Code:
$ pip --version
pip 9.0.1 from /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)

$ sudo pip install matplotlib
The directory '/Users/uz3r/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/uz3r/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting matplotlib
  Downloading matplotlib-2.2.2.tar.gz (37.3MB)
    100% |████████████████████████████████| 37.3MB 15kB/s
Collecting numpy>=1.7.1 (from matplotlib)
  Downloading numpy-1.14.2.zip (4.9MB)
    100% |████████████████████████████████| 4.9MB 110kB/s
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 3.2MB/s
Collecting python-dateutil>=2.1 (from matplotlib)
  Downloading python_dateutil-2.7.2-py2.py3-none-any.whl (212kB)
    100% |████████████████████████████████| 215kB 1.5MB/s
Collecting pytz (from matplotlib)
  Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
    100% |████████████████████████████████| 512kB 996kB/s
Requirement already satisfied: six>=1.10 in /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from matplotlib)
Collecting kiwisolver>=1.0.1 (from matplotlib)
  Downloading kiwisolver-1.0.1.tar.gz
Requirement already satisfied: setuptools in /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from kiwisolver>=1.0.1->matplotlib)
Installing collected packages: numpy, cycler, pyparsing, python-dateutil, pytz, kiwisolver, matplotlib
  Running setup.py install for numpy ... done
  Running setup.py install for kiwisolver ... done
  Running setup.py install for matplotlib ... done
Successfully installed cycler-0.10.0 kiwisolver-1.0.1 matplotlib-2.2.2 numpy-1.14.2 pyparsing-2.2.0 python-dateutil-2.7.2 pytz-2018.3
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ python
Python 3.6.4 (default, Dec 30 2017, 06:51:20)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
machdep: class is not implemented
>>> import matplotlib as plt
>>>
 

Andropov

macrumors 6502a
Original poster
May 3, 2012
746
990
Spain
I'm using MacPorts 2.4.2.

Which version of MacPorts ?

I tried it on my G5 with MacPorts 2.4.2 but it pulled in way more depencies :

---> Computing dependencies for py36-matplotlib
The following dependencies will be installed:
cython_select
fftw-3
nosetests_select
py36-altgraph
py36-cython
py36-macholib
py36-modulegraph
py36-nose
py36-numpy
py36-parsing
py36-py2app
py36-pyobjc
py36-pyobjc-cocoa
py36-tornado
qhull

Sorry, I meant that only one dependency failed to build (qhull), while the others were installed without a problem... even py36-obj, strangely.

Which version of MacPorts ?
I also tried with Macports 2.4.2 on my G4 Powerbook 12" but there it fails on qhull even when setting my GCC compiler to p-gcc49.

I had to change something else for it to work, as suggested here I modified qhull's portfile to look like this at the beginning:

Code:
PortSystem 1.0
PortGroup cmake 1.1
PortGroup compiler_blacklist_versions 1.0
cmake.out_of_source yes
cmake.set_osx_architectures no

So what worked for me on my G5 is installing Matplotlib via pip install

Code:
>>> import matplotlib
machdep: class is not implemented
>>> import matplotlib as plt
>>>

The problem arises when importing matplotlib.pyplot. Import matplotlib doesn't throw any errors.
I tried reinstalling matplotlib through pip though, but still crashes when importing pyplot.
 

Lastic

macrumors 6502a
Mar 19, 2016
879
757
North of the HellHole
I also tried compiling it from source but it keeps throwing that error.
First time I invoked it , it started building fonts.
Second time FontConfig also threw an error which was resolved by doing export LC_ALL=en_GB.UTF-8

However it keeps throwing that error

Code:
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file

When starting python -dv you can see which module actually crashes

Code:
# extension module 'matplotlib.ft2font' loaded from '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/ft2font.cpython-36m-darwin.so'
# extension module 'matplotlib.ft2font' executed from '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/ft2font.cpython-36m-darwin.so'
import 'matplotlib.ft2font' # <_frozen_importlib_external.ExtensionFileLoader object at 0x22c06f0>
# /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/__pycache__/mac_roman.cpython-36.pyc matches /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/mac_roman.py
# code object from '/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/__pycache__/mac_roman.cpython-36.pyc'
import 'encodings.mac_roman' # <_frozen_importlib_external.SourceFileLoader object at 0x22c0ad0>
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file
Abort trap

snelboek:~ uz3r$ locale
LANG="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_CTYPE="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_ALL="en_GB.UTF-8"

I had to manually set LC_ALL and LANG but looks like another issue described here

https://bugs.python.org/issue6202
 
Last edited:

Lastic

macrumors 6502a
Mar 19, 2016
879
757
North of the HellHole
So back to installing py36-matplotlib using Macports on my G4 using the adapted Portfile for qhull.
But then the matplotlib build fails ?

Code:
:info:build /usr/bin/gcc-4.2 -DNDEBUG -g -fwrapv -O3 -Wall -arch ppc -I/opt/local/include -I. -I/opt/local/Library/Frameworks/Python.framewor$
:info:build src/_macosx.m: In function ‘NavigationToolbar_get_active’:                                                                     pp$
:info:build src/_macosx.m:1313: error: ‘for’ loop initial declaration used outside C99 mode                                                   
:info:build error: command '/usr/bin/gcc-4.2' failed with exit status 1                                                                       
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_pyth$
:info:build Exit code: 1                                                                                                                     
:error:build Failed to build py36-matplotlib: command execution failed

How did you get it to build using Macports 2.4.2 ? Did you use variants ? I'm using Apple gcc-4.2 to build matplotlib, I tried with mp-gcc4.9 but that didn't work neither.

Regarding the error , I think you have to set your locale in Python like stated here before importing matplotlib.pyplot :

Code:
import locale
locale.setlocale(locale.LC_ALL, 'en_GB')

But I can't test it since py36-matplotlib won't build.
 

Andropov

macrumors 6502a
Original poster
May 3, 2012
746
990
Spain
How did you get it to build using Macports 2.4.2 ? Did you use variants ? I'm using Apple gcc-4.2 to build matplotlib, I tried with mp-gcc4.9 but that didn't work neither.

It seems like it uses C89 as a default and some files are using C99-like loops. I found a workaround, suggested here. Adding this line in matplotlib's port file adds the -std=c99 flag whenever it calls the compiler. I don't know if I used gcc-4.2 or 4.9 (probably the latter):

Code:
    compiler.blacklist gcc-4.0

    build.cmd CFLAGS=\"\$CFLAGS -std=c99\" && ${build.cmd}

    post-destroot {

Regarding the error , I think you have to set your locale in Python like stated here before importing matplotlib.pyplot :

Code:
import locale
locale.setlocale(locale.LC_ALL, 'en_GB')

But I can't test it since py36-matplotlib won't build.

I'll test this tomorrow (I'm out of town today), but seems promising. Thanks!
 
  • Like
Reactions: Lastic

Lastic

macrumors 6502a
Mar 19, 2016
879
757
North of the HellHole
It seems like it uses C89 as a default and some files are using C99-like loops. I found a workaround, suggested here. Adding this line in matplotlib's port file adds the -std=c99 flag whenever it calls the compiler. I don't know if I used gcc-4.2 or 4.9 (probably the latter):

Code:
    compiler.blacklist gcc-4.0

    build.cmd CFLAGS=\"\$CFLAGS -std=c99\" && ${build.cmd}

    post-destroot {

I'll test this tomorrow (I'm out of town today), but seems promising. Thanks!

I succeeded in building matplotlib using Macports with apple gcc4.2 with your suggestion BUT
even setting the locale doesn't help. Python still crashes and running locale in Terminal doesn't show the changed value when using locale.setlocale .

I think it's time to open a ticket for Macports .
 

dr.nils

macrumors newbie
Mar 20, 2019
1
2
Netherlands
I installed Python 3.6 and matplotlib (along with numpy, scipy, etc) through MacPorts on my iMac G4 but importing matplotlib.pyplot crashes python:

Code:
192:~ Raul$ python3
Python 3.6.5 (default, Mar 29 2018, 15:41:19)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
machdep: class is not implemented
terminate called after throwing an instance of 'std::runtime_error'
  what():  Couldn't close file
Abort trap
192:~ Raul$

Any idea why this happens?
Settings: iMac G4 1.25GHz, Mac OS X 10.5.8. Python 3.6.5. Matplotlib 2.1.1 installed through MacPorts with one dependency (qhull) installed with GCC 4.8 as 4.2 was blacklisted in MacPort's portfile.

I have found a workaround that works for me on my G5 mac. In font_manager.py you set

USE_FONTCONFIG = True.

Assuming you use macport you can find this file at
/opt/local//Library/Frameworks/Python.framework/Versions/3.x/lib/python3.x/site-packages/matplotlib/font_manager.py

where x denotes the version of your python version. I hope this helps others as well in order to keep their PPC Mac alive!
 
  • Like
Reactions: Traace and Lastic
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.