The Python "AttributeError: module 'ffmpeg' has no attribute 'input'" occurs
when you install the
ffmpeg module instead of
To solve the error, uninstall the
ffmpeg module and install
pip install ffmpeg-python.
The name of the module is
ffmpeg-python, even though the
import statement is
Open your terminal in your project's root directory and run the following commands to install the correct module.
ffmpegmodule as it clashes with
pip uninstall ffmpeg pip3 uninstall ffmpeg python -m pip uninstall ffmpeg python3 -m pip uninstall ffmpeg
Also, make sure the
python-ffmpeg module is not installed in the environment
as it also clashes with the
pip uninstall python-ffmpeg pip3 uninstall python-ffmpeg python -m pip uninstall python-ffmpeg python3 -m pip uninstall python-ffmpeg
You can verify that you don't have the
installed by running the following commands.
pip show ffmpeg pip show python-ffmpeg # or with pip3 pip3 show ffmpeg pip3 show python-ffmpeg
Now, also uninstall the
ffmpeg-python module to make sure it won't glitch due
to clashing with
pip uninstall ffmpeg-python pip3 uninstall ffmpeg-python python -m pip uninstall ffmpeg-python python3 -m pip uninstall ffmpeg-python
# 👇️ in a virtual environment or using Python 2 pip install ffmpeg-python # 👇️ for python 3 (could also be pip3.10 depending on your version) pip3 install ffmpeg-python
If you get a permissions error, run the command prefixed with sudo (on macOS) or
--user flag (all operating systems, outside a virtual environment).
# 👇️ if you get a permissions error sudo pip3 install ffmpeg-python pip install ffmpeg-python --user
If you don't have
pip in your PATH environment variable, run the
python -m pip install ffmpeg-python command.
# 👇️ if you don't have pip in your PATH environment variable python -m pip install ffmpeg-python # 👇️ for python 3 (could also be pip3.10 depending on your version) python3 -m pip install ffmpeg-python
If you need to install
conda, use the following command
# 👇️ for Anaconda conda install -c conda-forge ffmpeg-python
If you need to install
ffmpeg-python in Jupyter Notebook,
prefix the pip command with an exclamation mark.
# 👇️ for Jupyter Notebook !pip install ffmpeg-python
Once you install
ffmpeg-python, you can import and use it as follows.
import ffmpeg stream = ffmpeg.input('input.mp4') stream = ffmpeg.hflip(stream) stream = ffmpeg.output(stream, 'output.mp4') ffmpeg.run(stream)
The code sample assumes that you have an
input.mp4 file in the same location
If the error persists, rerun the installation command with the
pip install --ignore-installed ffmpeg-python pip3 install --ignore-installed ffmpeg-python # 👇️ if you don't have pip in your PATH environment variable python -m pip install --ignore-installed ffmpeg-python python3 -m pip install --ignore-installed ffmpeg-python
--ignore-installed option ignores the installed packages and overwrites
Make sure you don't have a local file called
ffmpeg.py in your project.
Your local file will clash with the
ffmpeg-python module and will shadow it.
If you have a local
ffmpeg.py file, rename it to something else, e.g.
Also, make sure to not name any variables
ffmpeg as that would also clash with
your import statement.
You can verify that you are importing the correct
ffmpeg module by passing it
import ffmpeg print(dir(ffmpeg))
Notice that the list of attributes contains the
input method, therefore we are
importing the correct
If you don't see the correct attributes in the list, then you are shadowing the
ffmpeg module by having a local
You can also access the
__file__ attribute on the imported module to get its
import ffmpeg # ✅ /home/borislav/Desktop/bobbyhadz_python/venv/lib/python3.10/site-packages/ffmpeg/__init__.py print(ffmpeg.__file__)
The module should be located in your
If you instead, get a path similar to the following:
The you are likely shadowing the real
ffmpeg-python module with a local
You can learn more about the related topics by checking out the following tutorials: