any ideas about "ImportError: no module named MacOS"

390 views
Skip to first unread message

Jonathan Hartley

unread,
Jun 8, 2012, 12:13:15 PM6/8/12
to pyglet...@googlegroups.com
I'm failing to install properly on OSX Snow Leopard, Python 3.2 32/64-bit .dmg from python.org.

Can anyone spot what I'm doing completely wrong? In particular, I'm using 'arch' to run my Python in 32-bit mode, but should I be installing a plain-old 32 bit Python? I'll try that next, but for now...

Running any of the pyglet examples gives:

$ python examples/graphics.py
Traceback (most recent call last):
  File "examples/graphics.py", line 50, in <module>
    from pyglet.gl import *
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/gl/__init__.py", line 235, in <module>
    import pyglet.window
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 1810, in <module>
    gl._create_shadow_window()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 493, in __init__
    display = get_platform().get_default_display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 1759, in get_default_display
    return pyglet.canvas.get_display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/canvas/__init__.py", line 82, in get_display
    return Display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/canvas/carbon.py", line 22, in __init__
    import MacOS
ImportError: No module named MacOS


The 'MacOS' module was removed from the stdlib in Python 3.x
http://docs.python.org/library/macos.html


How I got here is:

# get source from Hg, default branch:
$ hg clone https://code.google.com/p/pyglet/ pyglet
$ cd pyglet

$ mkvirtualenv -p python3.2 game
(game)$ python --version
Python 3.2.2

(game)$ python setup.py install
# This uses 100% of a CPU for 20 seconds, presumably doing the 2to3 conversion

(game)$ cd .. # to avoid importing the local source code
(game)$ python -c "import pyglet"
$ python -c "import pyglet"
Traceback (most recent call last):
...
ImportError: No module named objc
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
Exception: pyglet requires PyObjC when run in 64-bit Python; import objc failed

# To fix this, I ask OSX to run my Python binary in 32 bit mode:
(game)$ alias python='arch -i386 python'

# and try again
(game)$ python -c "import pyglet"

# seems to work! Yay! But...

$ python -c "import pyglet.window"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 1810, in <module>
    gl._create_shadow_window()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/gl/__init__.py", line 205, in _create_shadow_window
    _shadow_window = Window(width=1, height=1, visible=False)
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 493, in __init__
    display = get_platform().get_default_display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 1759, in get_default_display
    return pyglet.canvas.get_display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/canvas/__init__.py", line 82, in get_display
    return Display()
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/canvas/carbon.py", line 22, in __init__
    import MacOS
ImportError: No module named MacOS

Nathan

unread,
Jun 8, 2012, 1:17:24 PM6/8/12
to pyglet...@googlegroups.com
On Fri, Jun 8, 2012 at 10:13 AM, Jonathan Hartley <tar...@tartley.com> wrote:
> I'm failing to install properly on OSX Snow Leopard, Python 3.2 32/64-bit
> .dmg from python.org.
>
> Can anyone spot what I'm doing completely wrong? In particular, I'm using
> 'arch' to run my Python in 32-bit mode, but should I be installing a
> plain-old 32 bit Python? I'll try that next, but for now...

Sure, that's easy. Pyglet doesn't support Python 3.x yet.

~ Nathan

Andreas Schiefer

unread,
Jun 9, 2012, 3:04:29 AM6/9/12
to pyglet...@googlegroups.com
Well, that's not quite true. The version in the hg-repo supports
Python 3 for quite a while now (at least on Windows and Linux).
But I think Jonathan was the first one actually trying it on OSX.

I don't know much about MacOS, but I think it should use "cocoa" and
not "carbon" as indicated by the traceback. Maybe the check for
switching between those implementations fails in Python 3?

Jonathan Hartley

unread,
Jun 9, 2012, 12:56:22 PM6/9/12
to pyglet...@googlegroups.com
On Saturday, June 9, 2012 8:04:29 AM UTC+1, Andreas Schiefer wrote:
On Fri, Jun 8, 2012 at 7:17 PM, Nathan <n...stocks@gmail.com> wrote:
> On Fri, Jun 8, 2012 at 10:13 AM, Jonathan Hartley <t...y@tartley.com> wrote:
>> I'm failing to install properly on OSX Snow Leopard, Python 3.2 32/64-bit
>> .dmg from python.org.
>>
>> Can anyone spot what I'm doing completely wrong? In particular, I'm using
>> 'arch' to run my Python in 32-bit mode, but should I be installing a
>> plain-old 32 bit Python? I'll try that next, but for now...
>
> Sure, that's easy.  Pyglet doesn't support Python 3.x yet.

Well, that's not quite true. The version in the hg-repo supports
Python 3 for quite a while now (at least on Windows and Linux).
But I think Jonathan was the first one actually trying it on OSX.

I don't know much about MacOS, but I think it should use "cocoa" and
not "carbon" as indicated by the traceback. Maybe the check for
switching between those implementations fails in Python 3?


Acknowledged, and confirmed that under Python 2.7 it all works just fine.

Although I'm using a Mac as my primary laptop (work influences) I know so little about them that 'carbon' and 'cocoa' mean nothing to me. Given that caveat, I'll have a quick glimpse through the source to see whether it's obvious even to me why one is being chosen over the other. More if I figure anything useful.

Jonathan Hartley

unread,
Jun 9, 2012, 1:12:10 PM6/9/12
to pyglet...@googlegroups.com


One step forward:

Using the same alias 'python' to run in 32 bit mode:

$ python
Python 3.2.2 (v3.2.2:137e45f15c0b, Sep  3 2011, 17:28:58)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet
>>> pyglet.options['darwin_cocoa'] = True

>>> import pyglet.window
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/window/__init__.py", line 133, in <module>
    from pyglet.gl import gl_info
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/gl/__init__.py", line 220, in <module>
    from .cocoa import CocoaConfig as Config
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/gl/cocoa.py", line 11, in <module>
    from pyglet.libs.darwin import *
  File "/Users/jhartley/.envs/game/lib/python3.2/site-packages/pyglet/libs/darwin/__init__.py", line 5, in <module>
    from Foundation import *
ImportError: No module named Foundation
 

Andreas Schiefer

unread,
Jun 9, 2012, 1:53:40 PM6/9/12
to pyglet...@googlegroups.com
On Sat, Jun 9, 2012 at 7:12 PM, Jonathan Hartley <tar...@tartley.com> wrote:
> One step forward:
>
> Using the same alias 'python' to run in 32 bit mode:
>
> $ python
> Python 3.2.2 (v3.2.2:137e45f15c0b, Sep  3 2011, 17:28:58)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import pyglet
>>>> pyglet.options['darwin_cocoa'] = True
>
>>>> import pyglet.window
> Traceback (most recent call last):
[...]
> ImportError: No module named Foundation

I think you are missing PyObjC, but I've no experience with that.
Maybe you can try: http://code.google.com/r/evilphillip-cocoa-ctypes2/
As I understand it, this uses ctypes for interfacing with cocoa, not
requiring PyObjC.
And it seems, this will be soon the default implementation in pyglet,
according to this thread:
https://groups.google.com/d/msg/pyglet-users/fRYR_FUsrMQ/Y1T1MEKEOSoJ

Jonathan Hartley

unread,
Jun 10, 2012, 7:23:07 PM6/10/12
to pyglet...@googlegroups.com


Thanks for the ideas.

I wasn't yet able to get evilphilip-cocoa-ctypes2 to work under Python3.2:


$ arch -i386 python
Python 3.2.2 (v3.2.2:137e45f15c0b, Sep  3 2011, 17:28:58)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet
>>> pyglet.options['darwin_cocoa'] = True
>>> import pyglet.window
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/window/__init__.py", line 133, in <module>
    from pyglet.gl import gl_info
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/gl/__init__.py", line 220, in <module>

    from .cocoa import CocoaConfig as Config
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/gl/cocoa.py", line 15, in <module>
    from pyglet.canvas.cocoa import CocoaCanvas
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/canvas/__init__.py", line 90, in <module>
    from pyglet.canvas.cocoa import CocoaDisplay as Display
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/canvas/cocoa.py", line 15, in <module>
    from pyglet.libs.darwin.cocoapy import *
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/__init__.py", line 6, in <module>
    from .cocoapy import *
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/__init__.py", line 32, in <module>
    from .runtime import objc, send_message, send_super
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1100, in <module>
    class DeallocationObserver_Implementation(object):
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1101, in DeallocationObserver_Implementation
    DeallocationObserver = ObjCSubclass('NSObject', 'DeallocationObserver', register=False)
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 1007, in __init__
    self.objc_cls = create_subclass(superclass, name)
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 562, in create_subclass
    superclass = get_class(superclass)
  File "/Users/jhartley/.envs/adventure/lib/python3.2/site-packages/pyglet/libs/darwin/cocoapy/runtime.py", line 402, in get_class
    return c_void_p(objc.objc_getClass(name))
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type



As an alternative approach, I tried to install pyobjc from PyPI, but wasn't able to, not with pip (which is documented to not work), nor with easy install, even specifying older versions, nor downloading the source and running 'setup.py install', nor from the source in Hg. :-(

 
It's late though, I'm probably doing something dumb. Later, all.

  Jonathan

Nathan

unread,
Jun 10, 2012, 11:30:45 PM6/10/12
to pyglet...@googlegroups.com
On Sat, Jun 9, 2012 at 1:04 AM, Andreas Schiefer
<andreas....@gmail.com> wrote:
> On Fri, Jun 8, 2012 at 7:17 PM, Nathan <nathan...@gmail.com> wrote:
>> On Fri, Jun 8, 2012 at 10:13 AM, Jonathan Hartley <tar...@tartley.com> wrote:
>>> I'm failing to install properly on OSX Snow Leopard, Python 3.2 32/64-bit
>>> .dmg from python.org.
>>>
>>> Can anyone spot what I'm doing completely wrong? In particular, I'm using
>>> 'arch' to run my Python in 32-bit mode, but should I be installing a
>>> plain-old 32 bit Python? I'll try that next, but for now...
>>
>> Sure, that's easy.  Pyglet doesn't support Python 3.x yet.
>
> Well, that's not quite true. The version in the hg-repo supports
> Python 3 for quite a while now (at least on Windows and Linux).
> But I think Jonathan was the first one actually trying it on OSX.

Fascinating, I had not heard that.

~ Nathan
Reply all
Reply to author
Forward
0 new messages