Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing from custom package fails in Python

Tags:

python

So I have a main.py file inside /home/richard/projects/hello-python directory:

import sys
   sys.path.append('/home/richard/projects/hello-python')

   from Encode  import Ffmpeg
   x = Ffmpeg()
   x.encode()

I have then created a package in the /home/richard/projects/hello-python/Encode directory:

__init__.py
Ffmpeg.py

Init file is empty. Ffmpeg.py file contains:

class Ffmpeg(object):


   i = 150

   def __init__(self):
       print "i am constructor"

   def encode(self):
       print "hello world"

Now I run the main.py script like this:

python main.py

I get this output:

richard@richard-desktop:~/projects/hello-python$ python main.py 
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    x = Ffmpeg()
TypeError: 'module' object is not callable
richard@richard-desktop:~/projects/hello-python$ 

I think there is some problem with my sys.path so my module cannot be imported correctly but I am not sure how to fix it.

like image 829
Richard Knop Avatar asked Jul 16 '26 15:07

Richard Knop


1 Answers

from Encode.Ffmpeg import Ffmpeg
like image 80
bcelary Avatar answered Jul 19 '26 07:07

bcelary