ImportError: cannot import name 'FFProbe'
Asked Answered
Y

2

7

I can't get the ffprobe package to work in Python 3.6. I installed it using pip, but when I type import ffprobe it says

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python\Python36\lib\site-packages\ffprobe\__init__.py", line 1, in <module>
  from ffprobe import FFProbe
ImportError: cannot import name 'FFProbe'
  • The __init__.py file contains just the single line from ffprobe import FFProbe.

  • sys.path includes 'C:\Python\Python36\lib\site-packages', which is where the ffprobe directory is located.

  • Installing and importing the package works in Python 2.7 with no problems. But I would like to use it in Python 3, even if that means making manual changes to the .py files. (There is no documentation that says the package only works in Python 2.)

Can anyone help?

Yamen answered 28/5, 2017 at 12:35 Comment(5)
That import doesn't look right... It should work if you change it to from .ffprobe import FFProbe.Vermis
I changed __init__.py to that, and now the import works, but there are other errors that show the package is designed for Python 2 only. Anyway thank you for your answer. Could you tell me why from ffprobe import FFProbe works in Python 2 and why the dot is needed in Python 3?Yamen
I'm not sure about that either; python 2 import mechanics aren't something I'm overly familiar with. Who knows, maybe python 2 imports a different version of the module where the import is correct?Vermis
OK, thanks. But why did you guess that it would work with .ffprobe instead of ffprobe?Yamen
import module_name imports a module from python's library, whereas import .module_name imports a (sub-)module from the current module's directory. With from ffprobe import, the ffprobe module was importing itself, which makes no sense. With from .ffprobe import, it imports from the ffprobe.py file that's in the same directory as the __init__.py.Vermis
Y
2

The solution is that the ffprobe package only works with Python 2.

In Python 3 the import statement would need to be from .ffprobe ..., but just changing that is not sufficient as there are other lines that only work in Python 2 as well.

Thanks to Rawing.

Yamen answered 29/5, 2017 at 17:56 Comment(0)
C
9

Use this ffprobe package instead for Python3. Works for me: pip install ffprobe-python

Corona answered 3/5, 2020 at 22:4 Comment(0)
Y
2

The solution is that the ffprobe package only works with Python 2.

In Python 3 the import statement would need to be from .ffprobe ..., but just changing that is not sufficient as there are other lines that only work in Python 2 as well.

Thanks to Rawing.

Yamen answered 29/5, 2017 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.