question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:23 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
freakboy3742commented, Dec 4, 2017

@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
2reactions
freakboy3742commented, Dec 1, 2017

This has been corrected with Rubicon 0.2.10.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: 'ObjCInstance' object is not callable; Xcode ...
The issue is that the "stable" 0.2.15 version of Toga won't currently work on High Sierra or later - you need to use...
Read more >
TypeError: 'int' object is not callable (Mac) - python
Your error is that you called pygame.QUIT. Or, pygame.QUIT is a number. So you get an error. you must do it like this:...
Read more >
pycocoa
Package pycocoa. A basic, ctypes-based Python binding to the macOS Objective-C Cocoa runtime and several other macOS libraries.
Read more >
Rubicon Documentation
Objective -C objects are automatically returned as ObjCInstance objects, so you can call methods on them and access their properties. In some ...
Read more >
Keep your Mac up to date - Apple Support
Check for macOS updates, security updates, and updates to the built-in apps on your Mac.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found