Last updated: Apr 10, 2024
Reading timeยท3 min
The Python "AttributeError: module 'ffmpeg' has no attribute 'input'" occurs
when you install the ffmpeg
module instead of ffmpeg-python
.
To solve the error, uninstall the ffmpeg
module and install ffmpeg-python
by running pip install ffmpeg-python
.
The name of the module is
ffmpeg-python, even though the
import statement is import ffmpeg
.
Open your terminal in your project's root directory and run the following commands to install the correct module.
ffmpeg
module as it clashes with
ffmpeg-python
.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 ffmpeg-python
module.
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 ffmpeg
and python-ffmpeg
modules
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 ffmpeg
or python-ffmpeg
.
pip uninstall ffmpeg-python pip3 uninstall ffmpeg-python python -m pip uninstall ffmpeg-python python3 -m pip uninstall ffmpeg-python
ffmpeg-python
module.# ๐๏ธ 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
use the --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 ffmpeg-python
using conda
, use the following command
instead.
# ๐๏ธ 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
as your main.py
script.
If the error persists, rerun the installation command with the
--ignore-installed
flag.
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
The --ignore-installed
option ignores the installed packages and overwrites
them.
ffmpeg.py
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.
my-ffmpeg.py
.
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
to the dir()
function.
import ffmpeg print(dir(ffmpeg))
Notice that the list of attributes contains the input
method, therefore we are
importing the correct ffmpeg
module.
If you don't see the correct attributes in the list, then you are shadowing the
ffmpeg
module by having a local ffmpeg.py
file.
You can also access the __file__
attribute on the imported module to get its
location.
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 site-packages
directory.
If you instead, get a path similar to the following:
/home/borislav/Desktop/bobbyhadz_python/ffmpeg.py
The you are likely shadowing the real ffmpeg-python
module with a local
ffmpeg.py
file.
You can learn more about the related topics by checking out the following tutorials:
--no-cache-dir
option