Skip to content
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

AttributeError: 'NoneType' object has no attribute 'setDelegate_' #9

Closed
danisawesome opened this issue Jan 26, 2014 · 32 comments
Closed
Labels

Comments

@danisawesome
Copy link

When trying to run any of the examples, I'm running into this error:

Traceback (most recent call last):
File "queue_client.py", line 57, in
app.run()
File "/Users/danielschales/Envs/queue_client/lib/python2.7/site-packages/rumps/rumps.py", line 703, in run
NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self.nsapp)
AttributeError: 'NoneType' object has no attribute 'setDelegate
'

This is on a fresh install of Mavericks 10.9.1, using Homebrew installed Python 2.7.6, and installed PyObjC using pip all in a virtualenv. Using tito's fork as well as the official rumps repo. It was working in my previous Mavericks installation, but the system Python install was a mess, hence the reinstall and usage of a virtualenv this time around.

@danisawesome
Copy link
Author

Solved the issues. There was something weird with using virtualenvs for some reason and it works great without them. Not sure I understand why, but I'll take it!

@Melevir
Copy link

Melevir commented Sep 13, 2014

I have the same problem. And I like my virtualenv, it's so cozy!
May be there are ideas how to solve the issue?

@mrmachine
Copy link

Also unable to run the example inside a virtualenv. Same error as above.

@jaredks jaredks reopened this Dec 14, 2014
@jaredks jaredks added the bug label Dec 14, 2014
@jaredks
Copy link
Owner

jaredks commented Dec 14, 2014

Really a pyobjc issue but reopening as there may be a workaround.

>>> from Foundation import NSUserNotificationCenter
>>> NSUserNotificationCenter.defaultUserNotificationCenter() is None
True

@alexflint
Copy link

+1

1 similar comment
@kjagiello
Copy link

+1

@RyanBalfanz
Copy link

+1

Encountered this after #12 and #21

(venv2)➜  pyapp  python app.py
Traceback (most recent call last):
  File "app.py", line 17, in <module>
    AwesomeStatusBarApp("Awesome App").run()
  File "/Users/ryan/Desktop/pyapp/venv2/lib/python2.7/site-packages/rumps/rumps.py", line 1059, in run
    NSUserNotificationCenter.defaultUserNotificationCenter().setDelegate_(self._nsapp)
AttributeError: 'NoneType' object has no attribute 'setDelegate_'

@goodes
Copy link

goodes commented Jan 28, 2015

+1

3 similar comments
@toddwilson
Copy link

+1

@vink007
Copy link

vink007 commented Feb 9, 2015

+1

@scoates
Copy link

scoates commented Feb 27, 2015

+1

@scoates
Copy link

scoates commented Mar 2, 2015

FWIW, if I check out rumps manually and run some code from within the git checkout (read: if I don't use the pip-installed rumps), it works as expected.

@tvalliersbu
Copy link

+1

1 similar comment
@mileshiroo
Copy link

+1

@RyanBalfanz
Copy link

@scoates, As of now, there're 6 commits to master since v0.2.0 was released so you may be right. @jaredks, can you verify and push a new release to PyPI?

@aerickson
Copy link

+1 on this... would love to get it working.

Is there a pyobjc bug filed?

@jaredks Where does the fix you mentioned go? Thanks for making this project. :)

@gotlium
Copy link

gotlium commented Apr 7, 2015

+1

@zollman
Copy link

zollman commented Apr 19, 2015

The critical code snippet is

from Foundation import NSUserNotificationCenter
NSUserNotificationCenter.defaultUserNotificationCenter()

which appears to return None if you have the wrong application bundle properties / plist file.
(Seems to be an identical error to http://stackoverflow.com/questions/29341643/nsusernotificationcenter-defaultusernotificationcenter-returns-null-in-qt-applic )

The main python and virtualenv python are somehow different, even if you create your virtualenv with virtualenv --system-site-packages:

mybox:rumps-test user$ ls -l /usr/bin/python
-rwxr-xr-x  2 root  wheel  58608 May 20  2014 /usr/bin/python
(virtualenv)mybox:rumps-test user$ ls -l `which python`
-rwxr-xr-x  1 user  staff  34592 Apr 19 15:39 /Users/user/src/collector/virtualenv/bin/python

If I manually copy /usr/bin/python into my virtualenv, then this code snippet starts working (i.e., returns something other than None):

from Foundation import NSUserNotificationCenter
NSUserNotificationCenter.defaultUserNotificationCenter()

I can also get this working by putting an Info.plist file directly into the same bin dir as my virtualenv's python:

(virtualenv)mybox:bin user$ /usr/libexec/PlistBuddy -c 'Add :CFBundleIdentifier string "org.python.python"' Info.plist
(virtualenv)mybox:bin user$ cat Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleIdentifier</key>
    <string>org.python.python</string>
</dict>
</plist>

I have automated dynamic generation of this plist in a pull request:
#36

zollman pushed a commit to zollman/rumps that referenced this issue Apr 23, 2015
NSUserNotificationCenter.defaultNotificationCenter() returns None if there
is no CFBundleIdentifier in python's plist (MacOS app configuration) file.

The default system python has an associated plist; but pythons run in a
virtualenv do not.

This fix force-sets the CFBundleIdentifier field to be the application name
if it is not already set in the plist.
@mankoff
Copy link

mankoff commented May 17, 2015

@zollman confirming your fix works for me. I'm using the Anaconda (scientific) python from Continuum. Oddly ipython simple_example.py worked, but python simple_example.py did not. Adding the Info.plist to the anaconda/bin/ folder worked, or installing rumps from your bugfix-nobundleid branch works too. Thank you!

@zollman
Copy link

zollman commented Jun 3, 2015

Note for those browsing this: I closed my pull request -- while it prevents the specific error from being thrown, a dynamically-generated Plist won't actually give you the ability to throw real notifications on OS X. Works for the other use cases though.

@zefijsd
Copy link

zefijsd commented Jun 30, 2015

+1

5 similar comments
@etiology
Copy link

+1

@abyx
Copy link

abyx commented Sep 30, 2015

+1

@jdp
Copy link

jdp commented Oct 5, 2015

+1

@sabativi
Copy link

+1

@norcalli
Copy link

+1

@chrisfosterelli
Copy link

+1

@kennethreitz
Copy link

+1

1 similar comment
@wddwycc
Copy link

wddwycc commented Apr 26, 2017

+1

@jaredks
Copy link
Owner

jaredks commented Apr 30, 2017

Fix published to PyPI

@jaredks jaredks closed this as completed Apr 30, 2017
@kennethreitz
Copy link

\o/

@kennethreitz
Copy link

thank you @jaredks! Really looking forward to playing with this software now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests