Error Upgrading to Obspy 0.10.2_2 from 0.9.2_0

Hi,

Just to confirm that Gregory is not alone in this situation and to hopefully shed some new light on the issue. I am also having problems upgrading from @0.9.2_0+gcc48 to @0.10.2_2 on MacOSX 10.9.5.

I have tried installing/upgrading in every possible way (from binaries and source - uninstalling py27-obspy @0.10.2_2 and reinstalling, cleaning/reinstalling dependencies, etc.) and nothing has changed.

When activating @0.10.2_2 and importing obspy from within python (version 2.7.10), I get the same error message:

import obspy

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/__init__.py", line 38, in <module>
    __version__ = _getVersionString(abbrev=10)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/core/util/version.py", line 147, in get_git_version
    release_version = read_release_version()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/core/util/version.py", line 133, in read_release_version
    with io.open(VERSION_FILE, "rt") as fh:
LookupError: unknown encoding:

There is nothing else following “unknown encoding”. When I deactivate @0.10.2_2 and reactivate @0.9.2_0+gcc48, everything runs smoothly.

Regards,
Pascal Audet

Hi,

Could you please check what locale.getpreferredencoding() returns on your system

A quick look at the manpages of the io module (https://docs.python.org/2/library/io.html#io.open) indicates that when opening a stream in file mode and not specifying the encoding of the file, the io module uses whatever is returned by locale.getpreferredencoding(). The exception message seems to indicate that this is where something goes wrong. A look at the man page of the locale module ( https://docs.python.org/2/library/locale.html#locale.getpreferredencoding) gives "On some systems, it is necessary to invoke setlocale() to obtain the user preferences", perhaps this is the solution to the problem?

regP

Hi Peter, Pascal, and others,

Pascal, I’m glad I’m not alone in this error, and hopefully we can find a working solution.
I checked what locale.getpreferredencoding() returns on my system:

>>> [gbrenn:~]$Python 2.7.10 (default, Aug 29 2015, 19:04:03)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import locale
>>> locale.getpreferredencoding()
>>> ’ ’

>>>

Given that it returns northing when I call the preferred encoding, I imagine, like Peter said, we need to set the locale ourselves. So the next question is, what should we set the locale to?

Thanks for your help Peter.

Greg

Hi,

Alternatively you could try to modify the piece of code that caused the exception (better save an unedited version first ), e.g. in Pascal’s case at line 133 in file: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/core/util/version.py, try changing this line to: ����� with io.open(VERSION_FILE, “rt”, encoding=“UTF-8”) as fh: or whatever encoding is likely to be used on your system I note that io.open() is also used on line 144 as well as on lines 242 and 259 in file:�� /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/obspy/ndk/tests/test_ndk.py , thus edits may be needed there as well regP

Hi Peter, Pascal, and others,

Pascal, I'm glad I'm not alone in this error, and hopefully we can find a working solution.
I checked what locale.getpreferredencoding() returns on my system:

>>> [gbrenn:~]$Python 2.7.10 (default, Aug 29 2015, 19:04:03)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getpreferredencoding()
>>> ‘

Okay so this explains the issue pretty well. Thanks to Peter Schmidt for his insight.

However, this is still a bit wired, at least I. I am able reproduce the error by explicitly setting encoding=‘’, but not the condition where locale.getpreferredencoding() would give an empty string.

Just for curiosity, does this happen only with the MacPorts’ version of Python 2.7, or with the system’s version as well? What about Python 3.4?

Of cause, we could set encoding explicitly to “UTF-8” or “ascii” in this io.open() call, but I suspect somehow there are plenty of other occurrences where this surfaces again.

~petr

Hi all,

Thank you again for the help. Because I just got fed up with MacPorts, I completely uninstalled my Python version located in /opt/local, where MacPorts places the install. I also uninstalled all of the obspy packages related to the install using MacPorts, and related packages such as matplotlib and numpy. I also edited my path to remove the path to /opt/local/bin, where my MacPorts install of Python was located.

Once I purged my OS of any previous trace of Python (other than the already installed Python that came with Mavericks), I reinstalled Python, Obspy, matplotlib, and numpy using Homebrew. Homebrew was immensely easier to work with, and after editing environment variables in my ~/.profile to include /usr/local/bin, where my new Python version is located (and respective pacakges), everything is working fine, and the new install of Obspy 0.10.2 runs without any errors.

In summary, the previous issue must’ve had to do with Mac OSX 10.9.4 and the install using MacPorts, and I solved my problem by using Homebrew instead.

Cheers,
Greg