Reputation: 85
Background:
I have the following code, which should navigate to the mp3files
dir on my mac and then convert all .mp3
files to .wav
files.
Code:
import os
from pydub import AudioSegment
from ffprobe import FFProbe
path = "/Users/my_username/Documents/uc_davis/Homework_Repos/classify-spotify/william/mp3files"
os.chdir(path)
audio_files = os.listdir()
for file in audio_files:
name, ext = os.path.splitext(file)
if ext == ".mp3":
mp3_sound = AudioSegment.from_mp3(file)
mp3_sound.export("{0}.wav".format(name), format="wav")
Issue:
Upon running this code in Jupyter Lab, I get a ImportError: cannot import name 'FFProbe' from 'ffprobe' (/Users/my_username/anaconda3/envs/my_environment_name/lib/python3.7/site-packages/ffprobe/__init__.py)
What I've tried:
I have double-checked that I have the correct dependencies installed and the dir that the ImportError is referencing DOES have the correct files in it.
Does anyone have any suggestions what I am doing wrong?
Upvotes: 1
Views: 1227
Reputation: 36
I had this EXACT issue once, I went to: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/, which contains ffprobe.py
(which has FFProbe and stuff in it) and __init__.py
(which has from ffprobe import FFProbe
in it)
short version: Basically I changed the print x
statements inside ffprobe.py
to print(x)
statements by adding parentheses, and the from ffprobe import FFProbe
statement to from .ffprobe import FFProbe
longer version: I dragged and dropped ffmpeg.py
in and modified __init__.py
and gradually modified them to match ffprobe.py
until I found the problem. I noticed that the ffmpeg file's initialization contained periods so I copied that, and then started getting error messages around the print statements and fixed those too. Here's a pic w/ new on the left, init in middle, and old on the right if it helps at all...
Upvotes: 1
Reputation: 85
I removed from ffprobe import FFProbe
I re-ran my code, I had no issues. ffproble is not required.
Upvotes: 0