I have a package installed in /u/home/j/joelfred/python-dev-modules
. It looks like:
/a
__init__.py
b.py
The source for b.py
is simply:
def hello():
print('hi yourself')
And for __init__.py
:
import b
First, I make sure I'm in my home directory, and set my PYTHONPATH:
$ cd
$ export PYTHONPATH=/u/home/j/joelfred/python-dev-modules/
Then I run python3
:
$ python3
Python 3.4.3 (default, Mar 18 2015, 17:28:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/u/home/j/joelfred/python-dev-modules/a/__init__.py", line 1, in <module>
import b
ImportError: No module named 'b'
Okay, that's weird. But if I change __init__.py
to be blank:
$ python3
Python 3.4.3 (default, Mar 18 2015, 17:28:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import a.b as b
>>> b.hello()
hi yourself
>>>
What on earth is going on?