I'm using AudioSegment to create mp3 files in Python. It was working well but I recently change computer and now when I execute these lines :
from pydub import AudioSegment
sound = AudioSegment.from_wav("myfile.wav")
sound = sound.set_frame_rate(48000)
sound.export("myfile.mp3", format="mp3")
I have an error on the last line when exporting :
sound.export("myfile.mp3", format="mp3")
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Temp\ipykernel_29992\2926845828.py", line 1, in <cell line: 1>
sound.export("myfile.mp3", format="mp3")
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 963, in export
p = subprocess.Popen(conversion_command, stdin=devnull, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 109, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1416, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
The line in french say the file can't be found. Any idea how to fix ? I've installed the pydub and ffmpeg modules on this new computer. The script works fine on my previous computer. I'm using spyder.
Related
I am getting the below error trace when I am using PDFJinja's example for filling form fields in an existing PDF file.
Code Snippet:
dir_name = os.path.dirname("P:\\Project\\pdfjinja_services\\resources\\sample.pdf")
template_pdf_file = os.path.join(dir_name, 'sample.pdf')
template_pdf = PdfJinja(template_pdf_file, current_app.jinja_env)
print(type(template_pdf))
rendered_pdf = template_pdf({
'firstName': 'Faye',
'lastName': 'Valentine'
})
output_file = os.path.join(dir_name, 'output.pdf')
rendered_pdf.write(open(output_file, 'wb'))
Error:
Traceback (most recent call last):
File "P:\Professional\Python\CR\workspace\workspace-local\myplaybook\pdf_pdfjinja.py", line 10, in
rendered_pdf = template_pdf({
File "P:\Professional\Python\Softwares\python-3.9.6\lib\site-packages\pdfjinja.py", line 240, in call
filled = PdfFileReader(self.exec_pdftk(self.rendered))
File "P:\Professional\Python\Softwares\python-3.9.6\lib\site-packages\pdfjinja.py", line 212, in exec_pdftk
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
File "P:\Professional\Python\Softwares\python-3.9.6\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "P:\Professional\Python\Softwares\python-3.9.6\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
I am using python-3.9.6 and PDFJinja-1.1.0.
Please let me know if I am missing any other dependencies.
You are missing a binary (per update pdftk), or the binary is not in your search path.
I am using python 3.8.5 as well as the latest version of imagemagick and moviepy
error (vs code):
Traceback (most recent call last):
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\video\VideoClip.py", line 1137, in __init__
subprocess_call(cmd, logger=None)
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\tools.py", line 46, in subprocess_call
proc = sp.Popen(cmd, **popen_params)
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/edgib102/source/repos/Reddit-tts-video/Python/GetComments.py", line 40, in <module>
TextClip = TextClip('TextTxt', fontsize=100, color = 'white')
File "C:\Users\edgib102\AppData\Local\Programs\Python\Python38-32\lib\site-packages\moviepy\video\VideoClip.py", line 1146, in __init__
raise IOError(error)
OSError: MoviePy Error: creation of None failed because of the following error:
[WinError 2] The system cannot find the file specified.
.This error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file conf.py, or that the path you specified is incorrect
Code:
TextClip = TextClip('TextTxt', fontsize=100, color = 'white')
TextClip = TextClip.set_position('center').set_duration(10)
Any help at all would be much appreciated, also full code here
Solved. Just need to set the magick.exe file path as the variable inside default_config.py. You can find it in the moviepy folder.
Add the magick.exe path to IMAGEMAGICK_BINARY in config_defaults.py.
By default it should look like this
IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'auto-detect')
After
IMAGEMAGICK_BINARY = os.getenv('IMAGEMAGICK_BINARY', 'C:\\Program Files\\ImageMagick_VERSION\\magick.exe')
The following piece of code was working fine for a year, of late it intermittently started failing with following error, wonder if any OS or hardware change is causing this
import subprocess
def bash_command(cmd):
process = subprocess.Popen(cmd, shell=True, executable="/bin/bash")
process.wait()
bash_command("bash myscript.sh")
The error message is:
Traceback (most recent call last): File
"/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 68,
bash myscript.sh File "/Users/ishandutta2007/Documents/Projects/p2/shell_way/all_in_one_refill.py",
line 31, in bash_command
process = subprocess.Popen(cmd, shell=True, executable="/bin/bash") File
"/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 707, in __init__
restore_signals, start_new_session) File "/Users/ishandutta2007/.pyenv/versions/3.6.0/lib/python3.6/subprocess.py",
line 1326, in _execute_child
raise child_exception_type(errno_num, err_msg) OSError: [Errno 9] Bad file descriptor
I cannot use parameters when invoking date command inside Popen.
I am using Ubuntu 18.04.2 LTS, Python 3.6.7. I am trying to just print date by invokin date command from shell, unfortunately I got errors which says
Traceback (most recent call last):
File "./123.py", line 15, in <module>
print_date()
File "./123.py", line 9, in print_date
MyOut = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: "date '+%S'": "date '+%S'"
Code:
#!/usr/bin/python3
import subprocess
import time
import os
cmd = "date '+%S'"
def print_date():
MyOut = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout,stderr = MyOut.communicate()
print(stdout)
print(stderr)
os.system(cmd)
print_date()
Could anyone explain what went wrong, and why Python tries to find file "date '+%S'" ?
It works when we change cmd to cmd = "date", so what is correct way of passing '+%S' ?
The normal way to pass a command to Popen() is with a list. Try this:
cmd = ["date" '+%S']
completeProcess = subprocess.run("la")
This is my code to run commands via python, and it raise this error:
Traceback (most recent call last):
File "script_senior.py", line 171, in <module>
completeProcess = subprocess.run("la") # doesn't capture output
File "/usr/lib/python3.5/subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'la'
My OS is ubuntu, and when enter "la" in terminal, it will list files(include hidden files) in current working directory. and "ll" cmd will list file details. but I can't use them in python's subprocess api
How can I achieve this function? Is there any common api to run commands or just the python didn't recognize "la"
la is an alias for 'ls -A'. That comes as a default shell alias in systems like Ubuntu. If you wanna run it just use:
completeProcess = subprocess.run(["ls","-A"])
and if you are looking for the stdout you can use something like:
completeProcess = subprocess.run(["ls","-A"] , stdout=subprocess.PIPE)
print(completeProcess.stdout.decode())