midi2audio/FluidSynth: [WinError 2] The system cannot find the file - python

I get a FileNotFoundError error while trying to call midi2audio.
I am working with Python 3.6 - Anaconda - Windows 10.
My .py file is in the same folder, together with the .sf2 and the .mid files.
My code is:
from midiutil.MidiFile import MIDIFile
from midi2audio import FluidSynth
soundfont = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\JR_sax.sf2'
filepath = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\input.mid'
fs = FluidSynth(sound_font=soundfont, sample_rate=22050)
fs.midi_to_audio(filepath, 'output.wav')
I would expect a .wav file in my folder being created.
I get instead:
runfile('C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py', wdir='C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments')
Traceback (most recent call last):
File "<ipython-input-43-cdda6b922219>", line 1, in <module>
runfile('C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py', wdir='C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments')
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py", line 26, in <module>
fs.midi_to_audio(filepath, 'output.wav')
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\midi2audio.py", line 46, in midi_to_audio
subprocess.call(['fluidsynth', '-ni', self.sound_font, midi_file, '-F', audio_file, '-r', str(self.sample_rate)])
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Impossibile trovare il file specificato

soundfont = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\JR_sax.sf2'
filepath = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\input.mid'
Windows: \\ (why 2? Because \ is used by formatting like \n \r ... so you need 2)
Linux: /
If the file is in the same folder, then
soundfont = 'R_sax.sf2'
filepath = 'input.mid'
EDIT
I tried it on my PC (windows 10) and I get same error. I documentation I didnt find any mention about OS, but there is obviously some linux commands.
Try this on Linux OS
EDIT2
I put little effort and tried it on Linux too.
1) Error the same - File not found
2) I found out you have to put folder somewhere on the path -command: $PATH
I put it to /usr/local/bin/fluidsynth
3) New error: Permission denied (couldnt pass it even with root)
4) I found that I dont have fluidsynth installed
command: apt install fluidsynth
5) your script worked (kind of, output.wav generated)
Possible solution
I believe that the problem - after installing fluidsynth on the linux - that your solution for Windows will be solved after installing fluidsynth on windows.
http://www.fluidsynth.org/

Related

error trying to load exiftool

I have installed exiftool (https://smarnach.github.io/pyexiftool/) and I am able to import the library, but I get the following error when trying to run the test data just to see if it works.
ERROR: test_get_metadata (__main__.TestExifTool)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Program Files\Python36\Lib\site-
packages\pyexiftool\test\test_exiftool.py", line 66, in test_get_metadata
with self.et:
File "C:\Program Files\Python36\lib\site-packages\exiftool.py", line 191, in __enter__
self.start()
File "C:\Program Files\Python36\lib\site-packages\exiftool.py", line 174, in start
stderr=devnull)
File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I also did run the setup code that is in the exiftool folder and still no luck. I think it might be a library issue or path or the (init.py) file, but I've tried several ways and so I'm here to ask if anyone else has a solution or ideas for me to try and fix it.
I'm running Python 3.6.6 and have tried other versions.
(I can run exiftool in command line, but I have encoded BASE64 images that exiftool doesnt work in command line to fully decode.)
Thank you StarGeek! The problem was that I didn't have the exiftool command tool (the separate application of exiftool) in the right PATH env variable. Once I added the application to the PATH env variables i got it to work. Also in the python exiftool code at line 70 it says that you have to have it in the path or direct it to the executable, that I had missed. Thanks again!

How to run Openscad from windows command prompt

I am trying to run OpenScad through command prompt in windows 7. However I could not get it worked.
I added following directory to Path
"C:\Program Files\OpenSCAD\"
And tried to run the following script:
from os import listdir
from subprocess import call
files = listdir('.')
for f in files:
if f.find(".scad") >= 0: # get all .scad files in directory
of = f.replace('.scad', '.stl') # name of the outfile .stl
cmd = 'call (["openscad.com", "-o", "{}", "{}"])'.format(of, f) #create openscad command
exec(cmd)
Also I tried it with openscad, openscad.exe, openscad.com, no success so far.
The error I am getting is:
Traceback (most recent call last):
File "C:\Users\Desktop\scad2stl.py", line 9, in <module>
exec(cmd)
File "<string>", line 1, in <module>
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The specified file could not be found
Any suggestions?
I just saw this thread, I have make it work usign windows power shell, couldn't make it work on cmd due. So for example this doesn't work on cmd>
openscad -o render.png --imgsize=2048,2048 assembly.scad
but it does work on power shell (notice the ./ in the bigining):
./openscad -o render.png --imgsize=2048,2048 assembly.scad
hope it helps.
Best regards

Opening a network file in Cytoscape using cmd and Python

So I have a python script that produces a networkx graph and exports it as .graphml and I want script to also be able to open cytoscape with the network loaded without any work on the users part. I understand:
cytoscape.bat -N C:\Somepath\with\a\networkx.graphml
and it works fine when I use it. As does:
cd "C:\Program Files\Cytoscape_v3.0.0"
cytoscape.bat
However, I can't seem to get either os.system or subprocess to run properly, my current configuration is:
p = subprocess.Popen("cytoscape.bat", cwd="C:/Program Files/Cytoscape_v3.0.0")
stdout, stderr = p.communicate()
But the throws a file-not-found-exception.
I've been reading up on other stackoverflow posts and python docs on running .bats and doing cmd operations, and can get the basics to work. However, this seems somewhat more complicated, and I'm not sure where I'm going wrong!
As requested I exceptions:
The file not found and incorrect path exceptions:
Traceback (most recent call last):
File "CytoScapeExporter.py", line 219, in <module>
p = subprocess.Popen("cytoscape.bat", cwd="\"C:/Program Files/Cytoscape_v3.0
.0\"")
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 267] The directory name is invalid
Traceback (most recent call last):
File "CytoScapeExporter.py", line 219, in <module>
p = subprocess.Popen("cytoscape.bat", cwd="C:/Program Files/Cytoscape_v3.0.0
")
File "C:\Python27\lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
A slightly different JVM error, it is produced by this code:
os.system("\"C:/Program Files/Cytoscape_v3.0.0/cytoscape.bat\"")
Error: missing `server' JVM at `C:\Program Files (x86)\Java\jre7\bin\server\jvm.
dll'.
Please install or use the JRE or JDK that contains these missing components.
C:\Program Files\Cytoscape_v3.0.0
From the documentation:
"If cwd is not None, the child’s current directory will be changed to cwd before it is executed. Note that this directory is not considered when searching the executable, so you can’t specify the program’s path relative to cwd."
You have to pass the full path of the command to subprocess.Popen.

nmap script running error in python

i installed python-nmap-0.1.4.tar.gz in pyhton27 in window. When i ran this http://codepad.org/vTu1Uw7I script, i got a few error. What those error mean?. Are those error happened because i used python-nmap-0.1.4.tar.gz in windows?.
Here is the error
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/nmap/run-nmap.py", line 3, in <module>
nm = nmap.PortScanner() # instantiate nmap.PortScanner object
File "C:/Python27/Lib/site-packages/nmap\nmap.py", line 118, in __init__
p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Here is the subprocess.py script
http://codepad.org/SpbV8muR
Seems that python-nmap is meant to be run on Linux… but you can still try to make it work on Windows. The problem is that it is trying to call nmap but the binary is not found in PATH.
Add the directory with nmap executable to you PATH variable. Here is a HOWTO.

how to use subproces.Popen correctly on windows xp?- shows windowserror 2 while accessing npm

I am trying to run an existing python code, and having issues with it.
This program required npm program installed and which is installed at C:\Program Files\nodejs\npm in my computer. When I run the following code, as a part of the whole program, it throws errors.
def popen_results(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
return proc.communicate()[0]
def installed():
"""docstring for npm_installed"""
return popen_results(["which", "npm"]).strip()
This is the complete stack of the error thrown--
Checking for node and dependencies
Traceback (most recent call last):
File "deploy\deploy.py", line 344, in <module>
main()
File "deploy\deploy.py", line 287, in main
if not check_deps():
File "deploy\deploy.py", line 201, in check_deps
return npm.check_dependencies()
File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line
38, in check_dependencies
if not installed():
File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line
13, in installed
return popen_results(["which", "npm"]).strip()
File "C:\Documents and Settings\Sunil\workspace\khan\src\deploy\npm.py", line
8, in popen_results
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
File "C:\python25\lib\subprocess.py", line 594, in __init__
errread, errwrite)
File "C:\python25\lib\subprocess.py", line 822, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
I agree with martineau, it is unable to find which. The script may have been written with the assumption it was going to be run in a unix environment which would most likely have the "which" command available and in the default PATH. Since it looks like you're running this on Windows, I don't think it's going to work.
It looks like there is some alternatives to which on Windows though, discussed here: Is there an equivalent to which on Windows?

Categories