Skip to content

Simpler check for whether a Framework Python build is being used. #11851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/matplotlib/backends/backend_macosx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import os
import sysconfig

# PYTHONFRAMEWORK defined in CPython's configure.ac.
if not sysconfig.get_config_var("PYTHONFRAMEWORK"):
raise ImportError(
"Python is not installed as a framework. The MacOSX 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 MacOSX. 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 "
"'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the "
"Matplotlib FAQ for more information.")

from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import (
Expand Down
35 changes: 0 additions & 35 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -2563,38 +2563,6 @@ static void context_cleanup(const void* info)
Timer_new, /* tp_new */
};

static bool verify_framework(void)
{
#ifdef COMPILING_FOR_10_6
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSRunningApplication* app = [NSRunningApplication currentApplication];
NSApplicationActivationPolicy activationPolicy = [app activationPolicy];
[pool release];
switch (activationPolicy) {
case NSApplicationActivationPolicyRegular:
case NSApplicationActivationPolicyAccessory:
return true;
case NSApplicationActivationPolicyProhibited:
break;
}
#else
ProcessSerialNumber psn;
if (CGMainDisplayID()!=0
&& GetCurrentProcess(&psn)==noErr
&& SetFrontProcess(&psn)==noErr) return true;
#endif
PyErr_SetString(PyExc_ImportError,
"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 "
"'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the "
"Matplotlib FAQ for more information.");
return false;
}

static struct PyMethodDef methods[] = {
{"event_loop_is_running",
(PyCFunction)event_loop_is_running,
Expand Down Expand Up @@ -2644,9 +2612,6 @@ static bool verify_framework(void)
|| PyType_Ready(&TimerType) < 0)
return NULL;

if (!verify_framework())
return NULL;

module = PyModule_Create(&moduledef);
if (!module)
return NULL;
Expand Down