Obspy import triggers file execution.

Hi Obspy users,

I just set up a new system recently for scratch (OSX 10.9.5) and installed Anaconda and the obspy package as described on the website.

I found that my python executed 2 scripts each time I imported the module obspy.

As a small example (enclosed figure):
Screen Shot 2015-04-29 at 11.12.02 am.png

This only happens when I import Obspy, otherwise the python works fine and only one file is executed once I commend the import line.

I have inserted an error on purpose into the first file and get the following terminal message:

mgallt:Basemap mgal$ python test2.py
Traceback (most recent call last):
File “test2.py”, line 1, in
import obspy
File “/Users/mgal/anaconda/lib/python2.7/site-packages/obspy-0.10.1-py2.7-macosx-10.5-x86_64.egg/obspy/init.py”, line 36, in
from obspy.core.utcdatetime import UTCDateTime # NOQA
File “/Users/mgal/anaconda/lib/python2.7/site-packages/obspy-0.10.1-py2.7-macosx-10.5-x86_64.egg/obspy/core/init.py”, line 107, in
from obspy.core.util.attribdict import AttribDict
File “/Users/mgal/anaconda/lib/python2.7/site-packages/obspy-0.10.1-py2.7-macosx-10.5-x86_64.egg/obspy/core/util/init.py”, line 27, in
from obspy.core.util.base import (ALL_MODULES, DEFAULT_MODULES,
File “/Users/mgal/anaconda/lib/python2.7/site-packages/obspy-0.10.1-py2.7-macosx-10.5-x86_64.egg/obspy/core/util/base.py”, line 24, in
with standard_library.hooks():
File “/Users/mgal/anaconda/lib/python2.7/site-packages/future/standard_library/init.py”, line 323, in enter
install_hooks()
File “/Users/mgal/anaconda/lib/python2.7/site-packages/future/standard_library/init.py”, line 528, in install_hooks
install_aliases()
File “/Users/mgal/anaconda/lib/python2.7/site-packages/future/standard_library/init.py”, line 482, in install_aliases
import test
File “/Users/mgal/Python_codes/Basemap/test.py”, line 1
print 'Hello
^
SyntaxError: EOL while scanning string literal

Does anyone know why the import of obspy would trigger an import of test?

Kind regards,
Martin

University of Tasmania Electronic Communications Policy (December, 2014).
This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise.

Hi Martin,

This is caused by one of ObsPy's dependencies, namely python-future,
and the fact that your file name clashes with something provided by
the Python standard library.
Python-future is attempting to load the 'test' package, which comes
with some, but not all, packaged versions of Python. Because Python
searches the current directory (of the file running) first, it loads
your file.
If you rename your file to something that is not a standard name, then
you will not see this issue.

Hi Martin,

it is not ObsPy but in this case the future module which ObsPy imports…

There are a couple of Python packages in the wild that do “import test” and any file that is called “test.py” will be imported by that line. The problem is thus a consequence of Python’s import facilities but the packages could also do something against it.

Nonetheless in your case you should just rename the files as it causes too many issues.

Or you switch to Python 3 which defaults to absolute imports and the problem no longer exists.

Cheers!

Lion

Thank you very much. Deleting the file solved the issue.

Cheers,
Martin