After giving this some thought, I think I might know what's going on. In Python 2.x (I don't know about all Python 2 versions; for this example, I'm using Indigo 7 and Python 2.7). Consider two files, both of which reside in the same folder:
foo.py
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from foo1 import *
print(u"foo")
foo1.py
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
print(u"foo1")
When I run foo.py from the terminal, I get the following result:
- Code: Select all
Daves-MacBook-Air:Scripts dave$ python foo.py
foo1
foo
When I run foo.py as an embedded script within Indigo, I get the following result:
- Code: Select all
Script Error foo.py: No module named foo1
Script Error Exception Traceback (most recent call shown last):
foo.py, line 4, at top level
ImportError: No module named foo1
The Python interpreter will search the current folder (the one where the scripts reside) as a part of the search path, but it doesn't appear this is the case when running the script as an embedded script in Indigo. Further, there are rules about how imports work when the folder is considered a Python package (or not).
I believe there are a couple of different ways to handle your case (there are others but I think these are the best): you could write your code as a plugin, place your scripts in a folder included in the default sys.path, or you could use absolute imports as opposed to relative.
Here is a nice explanation of the ins and outs of Python imports.Any Python gurus out there (I'm not one) should feel free to correct anything I've said here.