Error while finding spec for 'fibo.py' (<class 'AttributeError'>: 'module' object has no attribute '__path__')

Viewed 47646

I have a module in a fibo.py file which has the following functions -

#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
    print()

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result

Now when I run the module from the cli python3 as -

> python3 -m fibo.py

I get the error

Error while finding spec for 'fibo.py' (<class 'AttributeError'>:
'module' object has no attribute '__path__')

The __path__ variable has has the current dir . I am not sure how to fix this.

3 Answers

These are two different ways to run a python 3 script:

python fibo.py: The argument is the name of the .py file.

python -m fibo: The argument is the name of a Python module, without .py

Related