Hi Matthew,

I actually ran into this last week so hopefully I can save you a few hours
of chasing things around with this.

This is being caused as a side effect of loading PyObjc in your
application, and then freezing it. Basically, PyObjc (the objc module)
loads the pkg_resources module from the distribute package to use some
helper functions. pkg_resources includes a class definition that has a
default argument set to a function which eventually causes the get_platform
function from distutils to be called. get_platform on OS X does something a
bit different from other operating systems - rather than just giving you
the current OS's version, it checks the Makefile of your Python install to
see what the MACOSX_DEPLOYMENT_TARGET was set to, and returns that version
instead. Since the Makefile isn't part of the frozen application (and I
don't think would be checked for there anyway) the call fails, leading to
your exception.

The kicker is that the class causing this isn't even used by PyObjc, it's
just a side effect of loading that pkg_resources module since it's in a
class definition in it.

It's a bit of a hack, but you can work around it easily using the
unittest.mock module on Python 3.3.x or the mock module on Python 2.5+ to
return a specific string when get_platform is called as part of loading
PyObjc. I set this to the right value on my system, though like I said, it
shouldn't really matter.

Basically, here's what I do, modified slightly for Python 2.7 (I'm using
Python 3.3):

import sys

if sys.platform == 'darwin':
    from mock import patch

    with patch('distutils.util.get_platform',
return_value='macosx-10.8-x86_64'):
        import objc

    <rest of your OS X code using objc>

I have the sys.platform part since the particular file that's in is shared
between platforms, you might not need it depending how you have your
project set up.

I figure even if this string was used, statically setting it like this for
just this import would be fine (nothing else goes into that context manager
block aside from the import) - since packaging the Makefile would
effectively set it statically for your distributed app anyway.

Hope this helps,

-Dan

--
Dan McCombs
Senior Software Engineer / Dyn
http://dyn.com/

Are you prepared for website disaster? Find out in two minutes:
http://dyn.com/dynedu-disaster-planning/


On Tue, Oct 15, 2013 at 6:13 AM, Matthew Tylee Atkinson <mat...@gmail.com>wrote:

> Thank you for cx_Freeze!  I am using it to (hopefully :-)) simplify my
> build process on Mac and Windows; looks very promising but I'm having some
> problems with it on the Mac side.  I have tried 4.3.1 and the latest code
> (just checked out).  I get the same problem on both.  I'm running Mountain
> Lion (10.8.5).
>
> The problem is that when I try to run the .app, I get this error:
>
> LSOpenURLsWithRole() failed with error -10810
>
> When I try to run the compiled script from within the .app, I get this
> stack trace:
>
> Traceback (most recent call last):
>   File
> "/Library/Python/2.7/site-packages/cx_Freeze-4.3.1-py2.7-macosx-10.8-intel.egg/cx_Freeze/initscripts/Console.py",
> line 27, in <module>
>     exec code in m.__dict__
>   File "AudioQuake.py", line 5, in <module>
>   File "/Library/Python/2.7/site-packages/GUI/__init__.py", line 49, in
> <module>
>     __import__(_testmod)
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/__init__.py",
> line 30, in <module>
>     from objc._bridgesupport import *
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/objc/_bridgesupport.py",
> line 9, in <module>
>     import pkg_resources
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
> line 698, in <module>
>     class Environment(object):
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
> line 701, in Environment
>     def __init__(self, search_path=None,
> platform=get_supported_platform(), python=PY_MAJOR):
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
> line 96, in get_supported_platform
>     plat = get_build_platform(); m = macosVersionString.match(plat)
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py",
> line 222, in get_build_platform
>     plat = get_platform()
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/util.py",
> line 98, in get_platform
>     cfgvars = get_config_vars()
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/sysconfig.py",
> line 498, in get_config_vars
>     func()
>   File
> "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/sysconfig.py",
> line 381, in _init_posix
>     raise DistutilsPlatformError(my_msg)
> distutils.errors.DistutilsPlatformError: invalid Python installation:
> unable to open /lib/python2.7/config/Makefile (No such file or directory)
>
> I've researched this and it seems most people (outside of the cx_Freeze
> context, at least) say this is a problem that occurs when the Python
> development package is not installed.  Surely the system Python should not
> be involved here, because cx_Freeze has just baked its own for me.  (To run
> the compiled script from within the app, I ran ./AudioQuake from within the
> Contents/MacOS directory.)
>
> I have tried the following steps to ease the problem…
>
> A. Removed the #! lines at the top of my scripts, so that the system
> Python is not being invoked.  I also removed the executable file permission
> attribute, and this had the effect of making the AudioQuake "binary" in the
> .app not executable, but when I used `chmod +x` on it, I got the same stack
> trace as above.)
>
> B. Explicitly used python2.7 as the command line when calling my cx_Freeze
> setup.py, in case there is some multi-headed-Python problem occurring.
>
> Neither step solves the problem.  I would be grateful for any pointers and
> I'd be happy to provide further information if needed, of course.
>
> Thanks for your time,
>
> Best regards,
>
>
>
> Matthew
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
> _______________________________________________
> cx-freeze-users mailing list
> cx-freeze-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
>
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
cx-freeze-users mailing list
cx-freeze-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cx-freeze-users

Reply via email to