从Python导入自定义包失败

时间:2012-06-26 15:56:10

标签: python

所以我在main.py file目录中有一个/home/richard/projects/hello-python

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

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

然后我在/home/richard/projects/hello-python/Encode目录中创建了一个包:

__init__.py
Ffmpeg.py

Init文件为空。 Ffmpeg.py文件包含:

class Ffmpeg(object):


   i = 150

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

   def encode(self):
       print "hello world"

现在我像这样运行main.py脚本:

python main.py

我得到了这个输出:

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$ 

我认为我的sys.path存在问题,因此我的模块无法正确导入,但我不确定如何修复它。

1 个答案:

答案 0 :(得分:7)

from Encode.Ffmpeg import Ffmpeg