Powerline: Homebrew upgrade to Python 2.7.10 breaks Powerline with ZSH

Created on 29 May 2015  Â·  15Comments  Â·  Source: powerline/powerline

After upgrading to Python 2.7.10, I get the following using default configs for powerline:

Last login: Thu May 28 19:56:33 on ttys000
2015-05-28 20:02:12,797:ERROR:shell:segment_generator:Failed to import attr hostname from module powerline.segments.common.net: dlopen(/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
  Referenced from: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/powerline/__init__.py", line 317, in get_module_attr
    return getattr(__import__(module, fromlist=(attr,)), attr)
  File "/usr/local/lib/python2.7/site-packages/powerline/segments/common/net.py", line 8, in <module>
    from powerline.lib.url import urllib_read
  File "/usr/local/lib/python2.7/site-packages/powerline/lib/url.py", line 9, in <module>
    from urllib2 import urlopen, HTTPError  # NOQA
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
    import mimetools
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
  Referenced from: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
2015-05-28 20:02:12,799:ERROR:shell:segment_generator:Failed to generate segment from {u'function': u'powerline.segments.common.net.hostname', u'priority': 10}: Failed to obtain segment function
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/powerline/segment.py", line 322, in get
    contents, _contents_func, module, function_name, name = get_segment_info(data, segment)
  File "/usr/local/lib/python2.7/site-packages/powerline/segment.py", line 69, in get_function
    raise ImportError('Failed to obtain segment function')
ImportError: Failed to obtain segment function

Reverting back to Python 2.7.9 fixes the issue for me. This feels like a packaging issue, but I figured I'd file here first since Powerline is the only thing I've noticed that's broken.

cshell serror in environment bug

Most helpful comment

I've got the same error today
Quick search on the internet brought me following solution:
Add following lines:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

to your ~/.bash_profile:

All 15 comments

It fails on importing urllib2. I think that python -c 'import urllib2' should also fail because core issue:

ImportError: dlopen(/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException

has absolutely nothing to do with powerline. If other things are not broken this means that they are not using urllib2, httplib, mimetools, tempfile or anything else that depends on io module.

AFAIR Mac OS can have two Python versions. Check whether /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so matches which python (if I am not mistaking this should be /usr/local/bin/python). Also check that output of ldd contains right path to libpython: it should contain something like

libpython2.7.so.1.0 => /usr/local/lib/libpython2.7.so (0xxxxxxxxxxxxxxxxx)

I'm using /usr/local/bin/python, urllib2 imports fine, and the library linking looks fine as well:

$ otool -L `which python`
/usr/local/bin/python:
    /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)

@deviantintegral What about vim -u NONE -i NONE -c 'python import urllib2'?

Also what is otool and how linking of the Python executable is relevant (if I understand the output correctly)?

@deviantintegral If python -c 'import urllib2' is fine, but vim … is not then I would suggest you to recompile Vim. Though I am not sure what is the problem: as far as I understand this Vim compiled with wrong Python version should emit different error and far earlier.

vim appears able to import urllib2 fine, but I'm not actually using powerline with vim.

otool is the OS X equivalent of ldd, so it's just showing that my python interpreter is linked to the right python library (different paths and names, because OS X).

@deviantintegral Do you use shell bindings with daemon (and did you restart it (it would be very strange if you got that error without restarting though))? Also

  1. Does powerline-render shell left work if you are using the daemon? If you are not, does powerline-daemon --foreground emit the same error when you run it and view prompt in _different_ window?
  2. What happens if you do python -c $'from powerline.shell import ShellPowerline\nfrom powerline.commands.main import get_argparser, finish_args, write_output\nfrom powerline.lib.encoding import get_unicode_writer\nimport os\nargs = finish_args(os.environ, get_argparser().parse_args())\nwrite_output(args, ShellPowerline(args, run_once=True), {"args": args, "environ": os.environ}, get_unicode_writer())' shell left (this is basically the same thing powerline-render is doing, but embedded directly in -c: if this variant works then you have something wrong with powerline scripts shebang)?

I do use powerline-daemon, and my shell is set to restart it every time I spawn a new zsh instance. When I run it in the foreground, the error is thrown in the new terminal instance, and not with the daemon itself.

I did some more tracing, and the error is being thrown when I source /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh, and not when rendering the prompt. From there, it's the call to zpython '_powerline_setup(globals())' that's triggering the exception.

@deviantintegral You do not use powerline-daemon. And you need to recompile zpython zsh module, because it is what you are using.

@deviantintegral And, by the way, that means that I actually needed to suggest testing with zsh -f -c 'zmodloab libzpython; zpython "import urllib2"' and not Vim.

BTW Homebrew/homebrew#40318.

I rebuilt zpython from homebrew's source to be sure it would link against the latest python. I had to modify your example a little, but it's throwing the same exception.

$ zsh -f -c 'module_path=($module_path /usr/local/lib/zpython); zmodload zsh/zpython; zpython "import urllib2"'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in <module>
    import httplib
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in <module>
    import mimetools
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in <module>
    import tempfile
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyErr_ReplaceException
  Referenced from: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Given that homebrew's zpython is unsupported, it sounds to me like this issue should be on hold or closed until it's updated.

@deviantintegral AFAIK changes to zpython due to update to 2.7.10 from 2.7.9 are not needed. I would rather blame 2.7.10 package for being strange and, possibly, buggy. But in any case it is clear that this is not a powerline issue.

You can disable zpython by using setting POWERLINE_NO_ZSH_ZPYTHON to one prior to sourcing bindings script. In this case using powerline daemon is highly suggested.

BTW, what did you mean by “my shell is set to restart it every time I spawn a new zsh instance”? If this is real restart then why? Note that if it is powerline-daemon --quiet (or _any_ other invocation of powerline-daemon without --kill or --replace arguments or their short forms) then this is _not_ a restart.

It turns out I'm not actually using zpython, so uninstalling it fixed the exception too.

I have the following in my ~/.zshrc:

module_path=($module_path /usr/local/lib/zpython) # Now can be removed
powerline-daemon -qk
powerline-daemon
. /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh

Thanks for all your help in tracking this down!

@deviantintegral I do not understand, what’s the point of killing daemon? This is normally needed only on updates. Also powerline-daemon --kill + powerline-daemon can be replaced with powerline-daemon --replace.

It turns out I'm not actually using zpython, so uninstalling it fixed the exception too.

If you were not using zpython then exception did not occur. Powerline by default only checks whether zpython is available (both old and new module name), it does not check whether it works, so no fallbacks.

So, how do i solve this? I've got the same issue

I've got the same error today
Quick search on the internet brought me following solution:
Add following lines:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

to your ~/.bash_profile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xfim picture xfim  Â·  15Comments

treyhunner picture treyhunner  Â·  16Comments

nfarrar picture nfarrar  Â·  11Comments

victorhck picture victorhck  Â·  11Comments

qoheniac picture qoheniac  Â·  12Comments