why am i getting error when importing AudioSegment?

23,773

Solution 1

Can u uninstall and try installing using pip install pydub. Also make sure pydub path is in the PYTHONPATH or system PATH. What OS are you using?

find out where pydub got installed.
I've in C:\Python27\Lib\site-packages\pydub.
Open a command-prompt and type in ,
set PATH=c:\Python27\Scripts;c:\Python27\Lib;C:\Python27\Lib\sit‌​e-packages\pydub;%PA‌​TH%

Then try running pydub program on cmd screen. Once successful you will need to add pydub path to system environment variables section.

Also for error:

RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)

Looks like pydub cant find ffmpeg or avconv. You may need to install or add path to system. If it's working I would let it be. It's just warning anyway

Solution 2

I was also getting the same issue .and it was coming due to ffmpeg was not correctly configured. i have download latest ffmpeg from official website https://www.ffmpeg.org/download.html and setting up the class path worked for me

Solution 3

I'm getting the same error because ffmpeg wasn't installed on my MAC. Installed it with brew install ffmpeg and it fixed the problem.

Solution 4

if you're using Linux, try this sudo apt install ffmpeg will fix the problem.

Hope it help !!!

Solution 5

Tried @paolov's solution - didn't work until I had restarted pycharm / python editor...

Also - see Python convert mp3 to wav with Pydub for quick alternative that doesn't necessary require pydub (but still needs ffmpeg)... involves import subprocess, thanks to @Roland Smith

PS - also, see http://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/ for description of how to add to PATH - in context of ffmpeg). I added to folder within my PyCharm/Python project instead of straight on C drive... either should work, but as I say, try restarting editor, and check cmd line > ffmpeg -codecs after adding to PATH...

Share:
23,773
Sh0z
Author by

Sh0z

BY DAYY : Senior in High School. BY NIGHTT: *code* > music > *code* > TV > *code* > sleep. "Life is better when your laughing". ~spread patience and love~

Updated on July 09, 2022

Comments

  • Sh0z
    Sh0z almost 2 years

    i'm trying to use pydub, but when i import it to python with AudioSegment it will give me an error saying it doesn't recognize it. i tried using pip install and searching online. any help?? i'm using python 2.7

    from pydub import AudioSegment
    
    • Liam
      Liam about 7 years
      try to install it from here: pypi.python.org/pypi/pydub#downloads
    • Anil_M
      Anil_M about 7 years
      can you post entire error-dump? , Also did the install was successful.
    • Sh0z
      Sh0z about 7 years
      error im getting: **libpng warning: sBIT: invalid. ** my code: import pydub from AudioSegment sound1 = AudioSegment.from_wave('chill.wav') sound2 = AudioSegment.from_wave('p1.wav') sound1= sound1[:] + 6 sound2=sound2+8 #louder combined = sound1.overlay(sound2) combined.export("pydubtry.wav", format='wav')
    • Sh0z
      Sh0z about 7 years
      would appreciate the help :) @Anil_M. i tried to install but it didn't work..
    • Sh0z
      Sh0z about 7 years
      @Liam the installation didn't work.. just opened a zip compress program. any suggestions??
    • Anil_M
      Anil_M about 7 years
      can u uninstall and try installing using pip install pydub. Also make sure pydub path is in the PYTHONPATH or system PATH. What OS are you using?
    • Sh0z
      Sh0z about 7 years
      @Anil_M thanks. i tried pip install but it's still giving me an error unfortunately. i use windows (10). by pydub in the path- do you mean the name of the folder itself? could you show an example please?
    • Sh0z
      Sh0z about 7 years
      @Anil_M btw this is what i get after installing with pip install: Successfully installed pydub-0.18.0 . is that what im meant to be getting?
    • Anil_M
      Anil_M about 7 years
      find out where pydub got installed. I've in C:\Python27\Lib\site-packages\pydub. Open a command-prompt and type in , set PATH=c:\Python27\Scripts;c:\Python27\Lib;C:\Python27\Lib\sit‌​e-packages\pydub;%PA‌​TH% . Then try running pydub program on cmd screen. Once successful you will need to add pydub path to system environment variables section.
    • Sh0z
      Sh0z about 7 years
      @Anil_M thanks for all the help it finally worked! do you by any chance know what this error means? RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning) ?
    • Anil_M
      Anil_M about 7 years
      Looks like pydub cant find ffmpeg or avconv. you may need to install or add path to system
    • Sh0z
      Sh0z about 7 years
      @Anil_M it looks like everything is working.. its creating all the files with the effects. should i look into this more?
    • Anil_M
      Anil_M about 7 years
      If it's working I would let it be. It's just warning anyway.
    • Sh0z
      Sh0z about 7 years
      thanks for all the help! @Anil_M
    • Anil_M
      Anil_M about 7 years
      Glad I could help. Up-voting comments will help me as well as the post.
    • Sh0z
      Sh0z about 7 years
      @Anil_M im new to this website, how do i do that?
    • Anil_M
      Anil_M about 7 years
      @Sh0z: I compiled my comments into an answer. You can upvote + accept that by selecting up arrow and selecting checkmark next to the question. This way the question will show as being answered and also will close the loop. That's better way to go about it.
    • Sh0z
      Sh0z about 7 years
      @Anil_M just voted. again thanks for all the help!! :)
  • Deepan Raj
    Deepan Raj about 5 years
    Can you elaborate what is seeting up the class path ? you mean download the ffmpeg and add the path to the environment variable or are there any procedure to install ffmpeg
  • Deepan Raj
    Deepan Raj about 5 years
    never mind, It worked. Adding ffmpeg\bin to the system path worked.
  • Amir Shabani
    Amir Shabani about 5 years
    The link is broken!
  • Willy satrio nugroho
    Willy satrio nugroho almost 4 years
    @user3251696 mean is adding the "../bin" path to the environment variables path in the control panel. *Note: This solution is for Windows users.