How do i set up midi2audio on Windows? - python

I'm trying to use the midi2sound python library, but i cant get it working!
it keeps spitting out the error FileNotFoundError: [WinError 2] The system cannot find the file specified whenever i try to convert a midi file to sound.
I don't really think there's anything that the script im using it in will provide, but here's a snippet that would cause this error for me:
from midi2audio import FluidSynth
fs = FluidSynth("Musical_Box.sf2")
fs.midi_to_audio("input.mid", "output.wav")
And yes, the midi file and soundfont file are in the same directory that the script is running in, so i honestly have no clue about what to do.
I've tried installing FluidSynth under (User)/.fluidsynth/ and putting a soundfont there too.
And yes, the midi file and soundfont file are in the same directory that the script is running in, so i honestly have no clue about what to do.
My preferred results from this would be to successfully convert a midi file to a wave file, or if not possible to at least find an alternative library

Ok, so, if you're on windows, you need to install FluidSynth, and put the path to it's executable in your PATH environment variable.
You can do this by searching for "Edit the system environment variables" and navigating to the environment variables area from there.
Double click on "Path" and inside that window click "New". Write the path to wherever the executable is stored, click "OK" until all windows are closed, and then restart your console or whatever IDE you're using so the changes can take effect.

Related

Can't find file: Errno 2 No such file or directory : Even after going to the correct directory and setting up the correct environment variable

I have set up the environment variable correctly and I am in the correct directory and I am still getting the following error:
C:\Users\Sherw\AppData\Local\Programs\Python\Python310\python.exe: can't open file 'C:\\Users\\Sherw\\OneDrive\\Desktop\\PycharmProjects\\Lab07\\venv\\Scripts\\cowsay.py': [Errno 2] No such file or directory
the cowsay.py file is in the directory C:\Users\Sherw\OneDrive\Desktop\PycharmProjects\Lab07\venv\Scripts so as you can see I am running the file from the correct directory.
'C:\Users\Sherw\AppData\Local\Programs\Python\Python310' I have added this path to the user environment variable.
I dont know why I am still getting the error.
Please let me know the solution to this problem.
Thank you very much.
Try relocating the cowsay.py into another folder alongside its dependencies, e.g. the downloads folder.
Open a cmd window and cd into C:\\Users\\YOURNAME\\Downloads(change YOURNAME to your usename)
Now use the command where python to get the path of the python executable you are actually running. Make sure that is where you think python.exe should be. Also at this point make sure you have installed python from python.org and NOT the microsoft store. If you installed from microsoft store uninstall from control panel and download python here instead. Delete any PATH changes you made beforehand and reboot if you needed to reinstall python.
After go back, open a cmd window and cd back into C:\\Users\\YOURNAME\\Downloads(change YOURNAME to your usename), and type python cowsay.py which should run. Try again in your venv location, although it is a really unconventional place to put your file in. If it works in the Downloads folder only it is an environment error and you may want to recreate the venv.

error when trying to run a code at pycharm and when typing pip at the cmd

I want to start with web development with python, django, react, javascript and when I download node.js at the windows PowerShell it showed me that its downloading python again and now when I want to run a code at PyCharm it is showing me this error:
Error running 'some new sobject': Cannot run program "C:\Users####\AppData\Local\Programs\Python\Python39\python.exe" (in directory ""): CreateProcess error=2, The system cannot find the file specified
or when I'm typing pip at the cmd it is showing me this error:
Fatal error in launcher: Unable to create process using '"c:\users????\appdata\local\programs\python\python39\python.exe" "C:\Users????\AppData\Local\Programs\Python\Python39\Scripts\pip.exe" ': The system cannot find the file specified.
I searched for some answers and nothing works should I redownload python?
as #Ruli said, it can be due to some special character in the File Name or a Folder, or it can be anything.
My suggestion is to move that whole folder that is default created by PyCharm, and move it somewhere like C:\ , so it is easier to locate the file and run it.
or if you have any other drive like D:\ or E:\ , move it there and try to run the program from the Command Line.

Opening Python and its files in Windows Powershell

I am currently reading the book Learn Python the Hard Way by Zed Shaw. On exercise 1 after learning the basics of Powershell we must open a notepad++ saved .py file in Powershell. Now here is the problem I'm having.
I am supposed to open this python file by running this command:
PS C:\Users\Trevor> python ex1.py
Zed Shaw does this in his book and it prints back what the file contains...("hello world")
Now i understand my path is wrong by the error message i receive telling me that python is not recognized. I have tried many many times to get the correct path to open python. I have saved the python27 file to my desktop and just about everything trying to get a path that will work.
I am starting at:
PS C:\Users\Trevor>
Any idea how to get to my python27 file and open python when it is saved to my desktop? I also have my ex1.py file saved to my python27 folder. Should i remove it? please help if you can thanks!
PowerShell cannot find python in the current directory or in the directories specified in PATH environment variable.
You can add your installed python directory to PATH variable in System Properties (Win+R → type in sysdm.cpl) → Advanced → Environment variables... → Under "user variables for ...", find PATH variable (if there aren't any, create it using New...), double click to edit it and insert "<your python path>;" (without the quotes). After that, restart PowerShell, run your command and you're done.
I also had this problem, but for me the solution to it wasn't creating a path. I typed in the same code as you, and this is the error message I got:
C:\Users\UserName\AppData\Local\Programs\Python\Python36\python.exe: can't open file 'ex1.py': [Errno 2] No such file or directory
The fix to this was a lot easier than I expected it to be, but it took me a little bit longer to figure out what it was since I just started learning how to work with Python and PowerShell.
This is what you need to do to solve this issue:
Instead of typing the name of the file you are trying to open, you first need to open the directory (the folder where all of your python files are stored).
To open the directory, type in cd DirectoryName and then press enter.
After that, type in "python" (without the quotes) and then the file name (for example, ex1.py). Then, press enter.
At this point, PowerShell should be able to open the file.
This is what you should see:
PS C:\Users\UserName> cd DirectoryName
PS C:\Users\UserName\DirectoryName> python FileName.py
(Note: This is when the file would print)
If your file still isn't opening, you may need to be more specific about the path to the directory. I have my directory located in C:\Users\UserName. If your directory is in C:\Users\UserName but you have it embedded within another folder, you may have to open that folder in PowerShell (you can do this by typing cd FolderName) before you can open the directory folder that's inside it. The easiest thing to do is to save your directory folder in the path C:\Users\UserName so that opening files will take less time/typing.

How do I read a text file in Pydev?

I'm doing a school assignment that requires me to read a file. I chose to use the Eclipse and Pydev combination because I really like the environment. However, no matter where I place the .txt file I get the following error: FileNotFoundError: [Errno 2] No such file or directory: 'file.txt' I've tried placing it in the src folder and the file directory. Something that I find quite odd is that if I were to run the same python module in IDLE, the file is found and read perfectly. Any help is appreciated!
You should put the file in the same folder as your .py file, if that doesn't work try to find out what directory it's currently using os.getcwd().
To fix this specifically:
Open Run Dialog...-> Select your run configuration->Arguments Tab->Working directory
EDIT:
import os
print os.getcwd()
If you cannot determine where to place your file - place it anywhere and use absolute path:
print(open(r'c:\your_file.txt', 'r').read())
If you've not played with your eclipse too hard you can just place your_file.txt in your project directory and use:
print(open('your_file.txt', 'r').read())
Update:
From one of your comments I've seen that you are doing sth extremely weird - look here:
You've somehow managed to open python.exe in your console window within eclipse and you edit files with eclipse but run it from python.exe directly on right hand side hence your code on the left has different environment if executed from eclipse and different when executed from right handside window.
Close that console and push PLAY button in your ECLIPSE:
You better first edit your files in something easier like notepad++. Just create your python source within directory whrer your python.exe resides and run that from command line with:
python.exe yoursource.py
Once you get a hang of how things work - switch to eclipse.
While working in notepad++ follow python tutorial
You simply are trying to do too many unknown to you things at the same time - this way you'll be scratching your head all day long
Pydev in Eclipse default working directory
Took me 10 seconds to find ;)
When you run your script from console it's this file directory, but from eclipse it could be another.

Getting Error can't find '__main__' module in 'X'

I made a simple hello program using Sublime Text. Run it using windows powershell but everytime I am getting error like :
C:\Python27\python.exe: can't find '__main__' module in 'X'
X is the name of folder. I have Python 2.7.4 Installed. How to fix it?
Maybe there's something wrong with your C:\Python27\python.exe.
See if there are two python under the folder C:\Python27:
python.exe
python2.7.exe.
If so, chose the python2.7.exe
Also possible if your module X is in anaconda or something similar, then you should adjust your Sublime environment to include anaconda (or whatever you're using).
Tools -> Build System -> New Build System
I know nothing about Python, other than running other people's Python apps on Windows occasionally. I see that this is an old thread, but still ran into this just now--the app threw this error and wouldn't run at all unless I included the '.py' extension on the command line.
This error can be caused by file corruption -- check that your module 'X' was copied correctly to the destination folder -- try opening it in an editor and make sure it looks ok. You will get this same error if you try to run Python on a file which is not a text file or a precompiled python module.
This problem is the same what I get last night, if you are using PyCharm to code Python, you can re-check the existing configuration, make sure in the working directory section it is filled in, and in the script path section, it is the same as the file location and file name.
Actually this is a problem where you have to write down the correct storage place.

Categories

Resources