python package confusion

Lipska the Kat lipska at
Mon Jul 23 12:02:58 CEST 2012

Hello again pythoners

I'm trying to understand the python package stuff

I have the following directory


In this directory I have two files, both executable


#! /usr/bin/env python3.2

# Fibonacci numbers module

def fib(n):    # write Fibonacci series up to n
     a, b = 0, 1
     while b < n:
         print(b, end=' ')
         a, b = b, a+b


#! /usr/bin/env python3.2

# fibo module test program

import fibo



The PYTHONPATH ev is set to /home/lipska/python/dev/mods:.
in .bashrc

The following interactive session works thusly

lipska at ubuntu:~/python/dev/mods$ python3.2
Python 3.2.3 (default, Jul 17 2012, 14:23:10)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import fibo
 >>> fibo.fib(1000)
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987

However if I try and run as an executable I get the following error

lipska at ubuntu:~/python/dev/mods$
Traceback (most recent call last):
   File "./", line 5, in <module>
NameError: name 'fib' is not defined

if I print sys.path I get the following

 >>> print(sys.path)
['', '/usr/local/lib/', '/usr/local/lib/python3.2', 

The documentation states that ...

sys.path is initialized from these locations:

     the directory containing the input script (or the current directory).
     PYTHONPATH (a list of directory names, with the same syntax as the 
shell variable PATH).

But apparently the additional locations I specify in .bashrc are not 
being added to sys.path

I also have an empty file in the mods directory

Not sure what I'm doing wrong here

Any help much appreciated.


Lipska the Kat: Troll hunter, Sandbox destroyer
and Farscape dreamer of Aeryn Sun.

More information about the Python-list mailing list