question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

name 'pydub' is not defined

See original GitHub issue

Pydub errors with Jupyter Notebook

from os import path
from pydub import AudioSegment

pydub.AudioSegment.converter = r"C:/ffmpeg/bin"

# Assign files                                                                         
src = 'C:/Users/liora/Documents/Engineering/3rd Year/Individual project (EG3005)/Music Genre Classification/archive/songs/misunderstood_lucky_daye.mp3'
dst = "C:/Users/liora/Documents/Engineering/3rd Year/Individual project (EG3005)/Music Genre Classification/archive/songs/output.wav"

# Convert wav to mp3                                                            
sound = AudioSegment.from_mp3(src)
sound.export(dst, format="wav")

The output I believe I should get is:

<_io.Bufferedrandom name='dst.wav'>

The error displayed:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-5-7a7c916717bd> in <module>
      2 from pydub import AudioSegment
      3 
----> 4 pydub.AudioSegment.converter = r"C:/ffmpeg/bin"
      5 
      6 # Assign files

NameError: name 'pydub' is not defined

My System configuration:

  • Python version: 3.9.5
  • Pydub version: 0.25.1
  • ffmpeg or avlib?: ffmpeg
  • ffmpeg/avlib version: 1.4

Is there an audio file you can include to help us reproduce?

I’m not sure how to attach it, but it’s an audio file that’s roughly 3 minutes long.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Kagirimcommented, Jun 7, 2022

Hello. Hope youre doing great! The win error 5 youre getting seems to be windows folder permissions. I’d try to run the python script under admin privileges or change the path of the source file to a non “C” one because that’s where most of the permission issues arise. You could also try to change the permission settings on the path folder. windows defender or antivirus might scream at you so I usually avoid placing external files in “C”. look at this as well How to fix - Error 5: Access is Denied in Windows 10 - Microsoft Community https://answers.microsoft.com/en-us/windows/forum/all/how-to-fix-error-5-access-is-denied-in-windows-10/8a4069ea-4b0e-4517-9d7a-62c44b4d6e7d happy if I was any help Thanks.

On Tue, Jun 7, 2022 at 10:50 AM psylockes @.***> wrote:

Thank you so much for the advice, the error is gone! But now I get this:


PermissionError Traceback (most recent call last) <ipython-input-59-af4d73abe6b6> in <module> 11 12 # Convert wav to mp3 —> 13 sound = AudioSegment.from_mp3(src) 14 sound.export(dst, format=“wav”)

~\anaconda3\envs\tensorflow\lib\site-packages\pydub\audio_segment.py in from_mp3(cls, file, parameters) 794 @classmethod 795 def from_mp3(cls, file, parameters=None): –> 796 return cls.from_file(file, ‘mp3’, parameters=parameters) 797 798 @classmethod

~\anaconda3\envs\tensorflow\lib\site-packages\pydub\audio_segment.py in from_file(cls, file, format, codec, parameters, start_second, duration, **kwargs) 764 log_conversion(conversion_command) 765 –> 766 p = subprocess.Popen(conversion_command, stdin=stdin_parameter, 767 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 768 p_out, p_err = p.communicate(input=stdin_data)

~\anaconda3\envs\tensorflow\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) 856 encoding=encoding, errors=errors) 857 –> 858 self._execute_child(args, executable, preexec_fn, close_fds, 859 pass_fds, cwd, env, 860 startupinfo, creationflags, shell,

~\anaconda3\envs\tensorflow\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 1309 # Start the process 1310 try: -> 1311 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1312 # no special security 1313 None, None,

PermissionError: [WinError 5] Access is denied

I’ve tried to change the permission on the folder but it’s not working, and I have conflicts while trying to update python in anaconda.

— Reply to this email directly, view it on GitHub https://github.com/jiaaro/pydub/issues/667#issuecomment-1148320485, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALQZCL6LCI56AGAX4QMNNKDVN35K3ANCNFSM5XOUNIUQ . You are receiving this because you commented.Message ID: @.***>

1reaction
Kagirimcommented, Jun 6, 2022

Hello. I believe this is because you imported the AudioSegment object from pydub so you should reference it directly ie AudioSegment.converter = r"C:/ffmpeg/bin" If you wanted to reference it as pydub.AudioSegment.converter = r"C:/ffmpeg/bin" change import statement to import pydub

Read more comments on GitHub >

github_iconTop Results From Across the Web

NameError: name 'pydub' is not defined - Using Streamlit
Wassup Guys, I try to create a document file uploader that also supports audio files (wav, mp3). (Want to save uploaded file temporarily ......
Read more >
Error with pydub in python - Stack Overflow
1 Answer 1 · 1. have you installed ffmpeg (ffmpeg.org)? · This library makes a call to the ffmpeg command. · i m...
Read more >
ModuleNotFoundError: No module named 'pydub'
pip install pydub.
Read more >
ModuleNotFoundError: No module named ... - RoseIndia.Net
ModuleNotFoundError: No module named 'pydub' ... How to remove the ModuleNotFoundError: No module named 'pydub' error? ... Hi,. In your python environment you...
Read more >
Working with wav files in Python using Pydub - GeeksforGeeks
wav audio files. Installation. This module does not come built-in with Python. To install it type the below command in the terminal. pip ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found