toga: "TypeError: 'ObjCInstance' object is not callable" on macOS High Sierra

In High Sierra (macOS 10.13), I am unable to use Toga or Toga-demo due to a TypeError. I was able to duplicate this on a fresh install of High Sierra in a VM; when I installed Toga and Toga-demo on a fresh install of Sierra (10.12), Toga and Toga-demo worked with no issues.

This has similar symptoms as issue https://github.com/pybee/toga/issues/154, but downgrading Rubicon has not solved the problem.

Details

Python Installation

$ uname -a
Darwin Andrews-Mac.local 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64
$
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$
$ CFLAGS="-I$(brew --prefix openssl)/include -O3" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install -v 3.6.3
...
Installed Python-3.6.3 to /Users/ame/.pyenv/versions/3.6.3
$ 
$ pyenv shell 3.6.3
$
$ python -V -V
Python 3.6.3 (default, Oct  9 2017, 17:43:29) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]

Virtualenv

$ python -m venv .venv
$
$ source .venv/bin/activate
$
$ pip install toga toga-demo
Collecting toga
  Downloading toga-0.2.15-py3-none-any.whl
Collecting toga-demo
  Downloading toga_demo-0.2.15-py3-none-any.whl
Collecting toga-cocoa; sys_platform == "darwin" (from toga)
  Downloading toga_cocoa-0.2.15-py3-none-any.whl
Collecting toga-core>=0.2.15 (from toga-cocoa; sys_platform == "darwin"->toga)
  Downloading toga_core-0.2.15-py3-none-any.whl (413kB)
    100% |████████████████████████████████| 419kB 2.6MB/s 
Collecting rubicon-objc>=0.2.8 (from toga-cocoa; sys_platform == "darwin"->toga)
  Downloading rubicon_objc-0.2.8-py3-none-any.whl
Collecting colosseum>=0.1.6 (from toga-core>=0.2.15->toga-cocoa; sys_platform == "darwin"->toga)
  Downloading colosseum-0.1.6-py3-none-any.whl
Installing collected packages: colosseum, toga-core, rubicon-objc, toga-cocoa, toga, toga-demo
Successfully installed colosseum-0.1.6 rubicon-objc-0.2.8 toga-0.2.15 toga-cocoa-0.2.15 toga-core-0.2.15 toga-demo-0.2.15

First Attempt

$ toga-demo
Traceback (most recent call last):
  File "/Users/ame/workspace/org.elgert/toga/.venv/bin/toga-demo", line 11, in <module>
    sys.exit(run())
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/__main__.py", line 5, in run
    main().main_loop()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 167, in main_loop
    self._startup()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 95, in _startup
    self._impl = NSApplication.sharedApplication()
TypeError: 'ObjCInstance' object is not callable
$ 
$ python
Python 3.6.3 (default, Oct  9 2017, 17:43:29) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from rubicon.objc import *                        
>>> NSBundle = ObjCClass('NSBundle')           
>>> NSBundle.mainBundle()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'ObjCInstance' object is not callable
>>> exit()

Downgrade Rubicon

Rubicon-objc==0.2.7

$ pip install rubicon-objc==0.2.7
Collecting rubicon-objc==0.2.7
  Downloading rubicon_objc-0.2.7-py3-none-any.whl
Installing collected packages: rubicon-objc
  Found existing installation: rubicon-objc 0.2.8
    Uninstalling rubicon-objc-0.2.8:
      Successfully uninstalled rubicon-objc-0.2.8
Successfully installed rubicon-objc-0.2.7
$
$ toga-demo
Traceback (most recent call last):
  File "/Users/ame/workspace/org.elgert/toga/.venv/bin/toga-demo", line 11, in <module>
    sys.exit(run())
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/__main__.py", line 5, in run
    main().main_loop()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 167, in main_loop
    self._startup()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 95, in _startup
    self._impl = NSApplication.sharedApplication()
TypeError: 'ObjCInstance' object is not callable

Rubicon-objc==0.2.6

$ pip install rubicon-objc==0.2.6
Collecting rubicon-objc==0.2.6
  Downloading rubicon_objc-0.2.6-py3-none-any.whl
Installing collected packages: rubicon-objc
  Found existing installation: rubicon-objc 0.2.7
    Uninstalling rubicon-objc-0.2.7:
      Successfully uninstalled rubicon-objc-0.2.7
Successfully installed rubicon-objc-0.2.6
$
$ toga-demo
Traceback (most recent call last):
  File "/Users/ame/workspace/org.elgert/toga/.venv/bin/toga-demo", line 7, in <module>
    from toga_demo.__main__ import run
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/__main__.py", line 2, in <module>
    from toga_demo.app import main
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/app.py", line 4, in <module>
    import toga
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga/__init__.py", line 114, in <module>
    set_platform()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga/__init__.py", line 86, in set_platform
    local_vars['platform'] = importlib.import_module(module_name)
  File "/Users/ame/.pyenv/versions/3.6.3/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/__init__.py", line 2, in <module>
    from .app import *
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 8, in <module>
    from .command import Command, Group
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/command.py", line 3, in <module>
    from .widgets.icon import Icon
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/widgets/icon.py", line 4, in <module>
    from ..libs import NSImage
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/libs/__init__.py", line 1, in <module>
    from .appkit import *
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/libs/appkit.py", line 232, in <module>
    NSColor.declare_class_property('alternateSelectedControlColor')
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/rubicon/objc/objc.py", line 1300, in __getattr__
    raise AttributeError('%s.%s %s has no attribute %s' % (type(self).__module__, type(self).__qualname__, self.objc_class.name, name))
AttributeError: rubicon.objc.objc.ObjCClass NSColor has no attribute declare_class_property

Rubicon-objc==0.2.4

$ pip install rubicon-objc==0.2.4
Collecting rubicon-objc==0.2.4
  Downloading rubicon_objc-0.2.4-py3-none-any.whl
Installing collected packages: rubicon-objc
  Found existing installation: rubicon-objc 0.2.6
    Uninstalling rubicon-objc-0.2.6:
      Successfully uninstalled rubicon-objc-0.2.6
Successfully installed rubicon-objc-0.2.4
$
$ toga-demo
Traceback (most recent call last):
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/rubicon/objc/objc.py", line 1274, in __getattr__
    return self.__dict__[name]
KeyError: 'declare_class_property'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/ame/workspace/org.elgert/toga/.venv/bin/toga-demo", line 7, in <module>
    from toga_demo.__main__ import run
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/__main__.py", line 2, in <module>
    from toga_demo.app import main
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_demo/app.py", line 4, in <module>
    import toga
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga/__init__.py", line 114, in <module>
    set_platform()
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga/__init__.py", line 86, in set_platform
    local_vars['platform'] = importlib.import_module(module_name)
  File "/Users/ame/.pyenv/versions/3.6.3/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/__init__.py", line 2, in <module>
    from .app import *
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/app.py", line 8, in <module>
    from .command import Command, Group
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/command.py", line 3, in <module>
    from .widgets.icon import Icon
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/widgets/icon.py", line 4, in <module>
    from ..libs import NSImage
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/libs/__init__.py", line 1, in <module>
    from .appkit import *
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/toga_cocoa/libs/appkit.py", line 232, in <module>
    NSColor.declare_class_property('alternateSelectedControlColor')
  File "/Users/ame/workspace/org.elgert/toga/.venv/lib/python3.6/site-packages/rubicon/objc/objc.py", line 1277, in __getattr__
    raise AttributeError('ObjCClass %s has no attribute %s' % (self.name, name))
AttributeError: ObjCClass NSColor has no attribute declare_class_property

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (8 by maintainers)

Most upvoted comments

@jfunez Unfortunately, the instructions @dgelessus gave won’t work - the Toga repository contains a number of sub-packages, and there’s no way to install the sub-packages directly from git. If you look at your pip freeze output, you’ve got an updated toga - but not toga-cocoa or toga-core, which is where the important bits are.

To install the development version of Toga, you need to run:

$ git clone https:///github.com/pybee/toga.git
$ cd toga
$ pip install src/core
$ pip install src/cocoa

This has been corrected with Rubicon 0.2.10.

On High Sierra, I used: pip install toga-demo==0.3.0.dev9 to get a working version.

On my MacBook running Sierra, 0.2.15 worked

I am trying pip3 install git+https://github.com/pybee/toga.git#subdirectory:/tree/master/src/cocoa

but I am receiving the following error, Could not find a version that satisfies the requirement toga-cocoa==0.3.0.dev5

How can I fix that, which commit in current development version I need to use?

@tourdownunder

  1. Clone toga
  2. Setup virtualenv like the instructions here https://pybee.org/contributing/how/first-time/setup/
  3. pip install -e src/core src/cocoa

Hi @freakboy3742 With the help of @Dayof I found a setup to get the examples working \o/ The working environment is:

$ pip freeze
colosseum==0.1.6
rubicon-objc==0.2.10
toga==0.2.15
toga-cocoa==0.3.0.dev1
toga-core==0.3.0.dev1

Thanks to everyone who helped me!

@jfunez As you might guess when you install a version of code direct from a Git repository, you’re going to find bugs sometimes 😃 We’re in the middle of a huge refactor, and there are still bugs in some areas of the code (the toga-demo is just one example).

You will probably have more luck looking in the examples directory of the Toga repository - those examples are more likely to be up to date.

@elgertam Thanks for the report. As you’ve noted, this is almost certainly a manifestation of the same problem as #154, which was in turned caused by pybee/rubicon-objc#40.

The problem is caused by subtle changes that Cocoa introduces between versions. Quoting @dgelessus from the Rubicon ticket:

The issue is that Objective-C has two syntaxes (method calling with [object name], and property access with object.name), and rubicon-objc maps both of them to Python attribute access. When there’s both a property and a method with the same name, rubicon-objc prefers the property. That means that if there’s a method called name, and in a future version a property called name is added, the meaning of object.name in rubicon-objc suddenly changes. However in Objective-C that change doesn’t affect existing programs, because the [object name] syntax still works, even if name is also a property.

When Sierra came out, NSBundle.mainBundle() and the NSColor predefined colors were modified into properties. This was fixed in 9faf7638

In this case, it looks like High Sierra has turned NSApplication.sharedApplication() into a property. The fix will be exactly the same as it was for NSBundle.mainBundle - explicitly declare the NSApplication.sharedApplication class property, then change references to be attributes, not method calls.