Installing pyfluidsynth on windows - python

I'm trying to install pyfluidsynth on windows. I used pip install pyfluidsynth in the command prompt, but when I tried to import fluidsynth in my python code I get:
ModuleNotFoundError: No module named 'FluidSynth'
When I tried to install FluidSynth (by using pip install fluidsynth) another binding package was installed with FluidSynth 0.2 from several years ago.
Can anybody help with specific details on how to install pyfluidsynth on windows and use it?
import FluidSynth
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm 2018.3.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'FluidSynth'

For recent FluidSynth versions there do not seem to be pre-built binaries for ms-windows available. (Note that development is now done on github; the sourceforge site is stale.) The latest source code releases are here.
But the FluidSynth wiki has instructions for building it on ms-windows.
Note: FluidSynth (more precisely, its shared library) is a requirement for using pyfluidsynth. See the README.

For me the following worked:
Go to the following link and download the pre-compiled (?) fluidsynth dll.
Add the directory of your fluidsynth dll to the path environment variable.
In the pyfluidsynth package. find the "fluidsynth.py" file, and edit the part where it's looking for the library "lib = find_library('fluidsynth')..." to search for the dll name, which was "libfluidsynth64" for the 64 bit version.
For whatever reason, (maybe version mismatch), the functions "fluid_synth_set_reverb_full" and "fluid_synth_set_chorus_full" are not supported, so comment those lines out from "fluidsynth.py".
And that's it. Save "fluidsynth.py" launch cmd, go into python, and import fluidsynth.
I haven't tested all the functionality of fluidsynth, but using pretty_midi, I was able to at least play midi through instrument soundfonts.
Hope this helps!

Installing fluidsynth on Windows
Download fluidsynth binaries from github: https://github.com/FluidSynth/fluidsynth/releases
Add extracted zip file’s bin to the path:
Eg: C:\Users*Your Username Here**** YOUR path to extracted zip ***\fluidsynth-2.1.6-win10-x64\bin
Download fluidsynth python library: the repository for python fluidsynth is:
https://github.com/nwhitehead/pyfluidsynth.
https://github.com/nwhitehead/pyfluidsynth/archive/master.zip
Once extracted, it must be installed:
python setup.py install
The extracted master.zip has fluidsynth.py This python file is the file to “import” into the python code. In the test folder it has example.sf2 which is used in an installation test: paths to these two files need to be set to your own locations.
import time
import fluidsynth
fs = fluidsynth.Synth()
fs.start()
sfid = fs.sfload("example.sf2")
fs.program_select(0, sfid, 0, 0)
fs.noteon(0, 60, 30)
fs.noteon(0, 67, 30)
fs.noteon(0, 76, 30)
time.sleep(1.0)
fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)
time.sleep(1.0)
fs.delete()
The above python code sample plays a single note. Getting this to work confirms everything is working.

For me, next works:
Call pip install --upgrade pyfluidsynth
Download precompiled DLL from: https://zdoom.org/downloads#Support
If you use 64x version rename file from libfluidsynth64.dll to libfluidsynth.dll
Place it into C:\Windows\System32

Related

raise NeedDownloadError('Need ffmpeg exe. ' NeedDownloadError: Need ffmpeg exe)

I'm trying to execute a call to an unofficial Instagram API python library, after several errors for dependencies needed I fixed, I'm stuck at this one.
File "C:\Users\Pablo\Desktop\txts_pys_phps_programacion\Instagram-API-python-master\InstagramAPI.py", line 15, in <module>
from moviepy.editor import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 20, in <module>
from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 15, in <module>
from moviepy.config import get_setting
File "C:\Python27\lib\site-packages\moviepy\config.py", line 38, in <module>
FFMPEG_BINARY = get_exe()
File "C:\Python27\lib\site-packages\imageio\plugins\ffmpeg.py", line 86, in get_exe
raise NeedDownloadError('Need ffmpeg exe. '
NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
Those final two lines in the error messages provide a valuable clue, and I installed moviepy only today so I remember a remedy.
NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
First (sudo) pip install imageio, if necessary.
Now: import imageio and then imageio.plugins.ffmpeg.download().
If you are using Ubuntu just try:
sudo apt-get install ffmpeg
Else if you are using Windows just try to change ffmpeg.py 82th line from auto=False to auto=True
It will automatically download ffmpeg to the correct path once. Then import imageio and write down imageio.plugins.ffmpeg.download()
Will work.
This package relies on the ffmpeg executable to be in the PATH.
So just download it, install it somewhere, and add installation directory to PATH. make sure it can be accessed by typing:
ffmpeg
from the command line.
For anyone using a mac do this.
pip install imageio (if not already installed).
Then create a .py file (python script).
In this file write this:
import imageio
imageio.plugins.ffmpeg.download()
Run this script in the terminal (i.e "python (insert .py filename here)" )
It installs FFmpeg in a directory that should be automatically added to your path. If not, add it to your path.
Then type
ffmpeg
to make sure it's installed in your path.
At Windows, I'd fix this that way:
Manual download ffmpg from github
In the Lib\site-packages\imageio\plugins\ffmpeg.py file, change
exe = get_remote_file('ffmpeg/' + FNAME_PER_PLATFORM[plat], auto=False)
to
exe = "PATH_WITH_FFMPG\\ffmpeg.win32.exe"
on mac,
this is the best way to install ffmpeg.
Open terminal and type.
$ brew install ffmpeg
you will be seeing it get installed.
==> Installing dependencies for ffmpeg: lame, x264, xvid

How to alter setup.py for CyIPOPT

I want to install the python package CyIpopt (https://github.com/matthias-k/cyipopt) on windows 10 and python version 3.5.2. For the binary I am using http://www.coin-or.org/Binaries/Ipopt/Ipopt-3.10.1-Win32-Win64-dll.7z (which I unpacked). The github page gives install instructions. At one point it says:
Download the source files of cyipopt and update setup.py to point to the header files and binaries of the Ipopt package, if LD_LIBRARY_PATH and pkg_config are not setup to find ipopt on their own.
I downloaded the source files from github and edited the setup.py file by altering lines 33-36 to :
IPOPT_ICLUDE_DIRS=['D:\...\Ipopt-3.10.1-Win32-Win64-dll\include\coin', np.get_include()]
IPOPT_LIBS=['IpOptFSS','IpOpt-vc10','IpOpt-vc8']
IPOPT_LIB_DIRS=['D:\...\Ipopt-3.10.1-Win32-Win64-dll\lib\\x64\Release MKL']
IPOPT_DLL=['IpOptFSS.dll','IpOpt-vc10.dll','IpOpt-vc8.dll']
The dots represent the path to these folders on my computer. Now when I run python setup.py install, it run succesfuly. However when I then run python and import ipopt I get the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Linthorst\Miniconda3\lib\site-packages\ipopt-0.1.6-py3.5-win-amd64.egg\ipopt__init__.py", line 40, in
from cyipopt import *
ImportError: No module named 'cyipopt'
I suspect I altered the setup.py file incorrectly (since I made an educated guess). I am confused that it installed but doesn't work. Can anybody help me solve this error? Many thanks in advance

Unable to import git in python

I am facing these issues. Can you help me with the same ?
Why am I seeing this error ? Do I have to add anything in the requirements.txt file ?
>>> import git
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
import git
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
>>> from git import Repo
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
from git import Repo
File "git\__init__.py", line 29, in <module>
_init_externals()
File "git\__init__.py", line 23, in _init_externals
raise ImportError("'gitdb' could not be found in your PYTHONPATH")
ImportError: 'gitdb' could not be found in your PYTHONPATH
I already had gitdb and smmap installed so I had to reinstall them.
You can reinstall them by running the following command in your terminal:
pip3 install --upgrade --force-reinstall gitdb; pip3 install --upgrade --force-reinstall smmap
I also got the message ImportError: 'gitdb' could not be found in your PYTHONPATH (when trying to use GitPython).BUT I had gitdb already installed!
Thanks to this hint I figured out that gitdb silently failed because it was missing smmap.
So I installed this and it worked.
You need to install gitdb package.
$ sudo easy_install gitdb
I had the same problem. However, gitdb and smmap were already installed by pip. As I used brew to install python and its dependencies on my mac, when I checked brew doctor command, it said that my /usr/local/sbin directory is not in my PATH. So I added it to my PATH (though it didn't have anything to do with the python) and everything worked out eventually.
MS Windows Versions of this problem can occur because of the order of Python versions in your system PATH, as it did for me. I did not realize that when I installed another program, it installed a newer version of Python for its own usage, and it appended my system PATH with the address to the newer version. I noticed it when I looked at the PATH variable and found two versions of Python being called. Windows uses the first it finds, and if the first doesn't match what your program expects, it gets confused and can't find the right path to the module. This is what I did to resolve it:
To check: an easy way to test if this is your problem is to see if the paths separated by semicolons are in the right order. That can be seen in the System Variables of Windows or by printing your PATH variable in your CMD shell like in this example:
C:> path
PATH=C:\Program Files (x86)\Python37-32\Scripts;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\WINDOWS
Temporary solution:
To see if it is going to fix your computer, change it in your CMD window. Your variable change will be discarded when the window is closed. One way to do this test is to copy the paths, move the Python references to the order they are needed, and write it back:
C:> set path = C:\WINDOWS;C:\Program Files (x86)\Python37-32;C:\Program Files\Python38\Scripts;C:\Program Files (x86)\Python37-32\Scripts\
Then run the Python program to see if this was your problem. Note that this is only an example; do not copy & paste it. Your path is customized for the programs on your computer.
Permanent solution: If the above test resolves your problem, you must change your System Variables to make the change permanent. For me that usually requires a reboot afterwards in order to make the variables appear in all new windows.

Python: OSError: cannot load library libcairo.so.2

I'm having some trouble running a python script on my Windows 7 platform. I've installed Python and also cairo, last one using "pip". I'm running the script using this command:
C:\Python34>python.exe label/make_label.py
and I get the following error message:
Traceback (most recent call last):
File "label/make_label.py", line 6, in <module>
import cairocffi as cairo
File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 41, in <modul
e>
cairo = dlopen(ffi, *CAIRO_NAMES)
File "C:\Python34\lib\site-packages\cairocffi\__init__.py", line 34, in dlopen
return ffi.dlopen(names[0]) # pragma: no cover
File "C:\Python34\lib\site-packages\cffi\api.py", line 118, in dlopen
lib, function_cache = _make_ffi_library(self, name, flags)
File "C:\Python34\lib\site-packages\cffi\api.py", line 411, in _make_ffi_libra
ry
backendlib = _load_backend_lib(backend, libname, flags)
File "C:\Python34\lib\site-packages\cffi\api.py", line 400, in _load_backend_l
ib
return backend.load_library(name, flags)
OSError: cannot load library libcairo.so.2: error 0x7e
What I've already done is the following:
Added the PATH to GTK/bin in the environmental variable
I check the folder GTK/bin and found "libcairo-2.dll" so I renamed it to libcairo.so
I don't know what other information could be useful in solving this but please let me know and I'll try to add it.
On Mac OS X using homebrew:
brew install cairo
brew install pango
It seems cairo depends a shared library which is not in standard search library, however, the python is calling dlopen to dynamic load the library, so you could try to put the libcairo.so.2(if it's a link, then make sure the reference locates at the same folder) in the working directory. You can also try pkg-config to set the environment. see here http://people.freedesktop.org/~dbn/pkg-config-guide.html
I just had the same issue ("OSError: cannot load library libcairo.so.2: error 0x7e"), and this is how I solved the problem on Windows (Windows 7 x64, Python 3.4.2 x86 (MSC v.1600 32 bit)):
downloaded an all-in-one bundle of the GTK+ stack including 3rd-party dependencies (which contains libcairo-2.dll and other Cairo-related libraries)
extracted this archive to a path which does NOT contain spaces (e.g. C:\Programs\gtk+)
added the extracted directory's bin subdirectory (which contains the mentioned libcairo-2.dll and other necessary files) to the PATH
Win+R, SystemPropertiesAdvanced
Environment Variables...
added this directory to the Path variable (either to the user variables or system variables, after a semicolon) (e.g. ...;C:\foo;C:\Programs\gtk+)
OK
pip install cairosvg
tested it with a very simple code, which already had worked:
import cairosvg
testsvg = '<svg height="30" width="30">\
<text y="10">123</text>\
</svg>'
svgConvertedToPng = cairosvg.svg2png(bytestring=testsvg)
print(svgConvertedToPng)
Solved on Windows 10 as follows:
download the headless UniConverter installer
Find where it installed and add its dll subdirectory to the system path.
Close and re-open the command window to get the updated path.
I just fixed this on Mac OSX 10.13 with an Anaconda Python installation and cairosvg:
$ conda install cairo pango gdk-pixbuf libffi cairosvg
$ cairosvg image.svg -o image.png
I got the idea from https://cairosvg.org/documentation/, which says that all its dependencies can be installed with WeasyPrint. WeasyPrint's documentation for installation on MacOSX at https://weasyprint.readthedocs.io/en/latest/install.html#macos says to get the dependencies from HomeBrew:
brew install python3 cairo pango gdk-pixbuf libffi
So I tried it with conda instead and it worked fine.

Python: Installation issues with pygraphviz and graphviz

I see many questions on the difficulties of properly installing pygraphviz and graphviz on Windows for Python 2.7. But no answers that I have found is solving my problem. Here's what I did:
I first installed pygraphviz using unofficial windows binaries
with this link in my anaconda (python) folder (
C:\Users\chamar\AppData\Local\Continuum\Anaconda )
Downloaded graphviz-2.36.msi and installed it under the default
path C:\Program Files (x86)\Graphviz2.36
The command import pygraphviz in Python works. But when I want to use say this function nx.graphviz_layout I get raise ValueError("Program %s not found in path."%prog)
What may cause this problem is that pygraphviz cannot locate the path of graphviz. Now, since I installed pygraphviz using the unofficial windows binary, which file can I modify to link both the library and include for graphviz's path? You would you usually find in the setup.py of pygraphviz the library and include paths when you don't use the unofficial binaries.
UPDATE 1
I added to PATH in Regedit under SOFTWARE a folder GRAPHIZ with a new key (default) with value C:\Program Files (x86)\Graphviz2.36\bin
UPDATE 2
I was having an error in the pydot.py file regarding the difficulty of Python locating the path of Graphviz. I made the changes as follow:
def _graphviz():
if os.sys.platform == 'win32':
path = r"C:/Program Files (x86)/Graphviz2.36/bin/"
progs = __find_executables(path)
return progs
find_graphviz()
{'fdp': 'C:/Program Files (x86)/Graphviz2.36/bin/fdp.exe', 'twopi': 'C:/Program Files (x86)/Graphviz2.36/bin/twopi.exe', 'neato': 'C:/Program Files (x86)/Graphviz2.36/bin/neato.exe', 'dot': 'C:/Program Files (x86)/Graphviz2.36/bin/dot.exe', 'circo': 'C:/Program Files (x86)/Graphviz2.36/bin/circo.exe'}
That seems ok with me but when I execute say:
positions = nx.graphviz_layout(G, prog='twopi', root=0)
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\networkx\drawing\nx_agraph.py", line 229, in graphviz_layout
return pygraphviz_layout(G,prog=prog,root=root,args=args)
File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\networkx\drawing\nx_agraph.py", line 264, in pygraphviz_layout
A.layout(prog=prog,args=args)
File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1305, in layout
data=self._run_prog(prog,' '.join([args,"-T",fmt]))
File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1251, in _run_prog
runprog=r'"%s"'%self._get_prog(prog)
File "C:\Users\chamar.stu\AppData\Local\Continuum\Anaconda\lib\site-packages\pygraphviz\agraph.py", line 1239, in _get_prog
raise ValueError("Program %s not found in path."%prog)
ValueError: Program twopi not found in path.
Why?
Here are the steps I followed to get pygraphviz working for Python 3.4 (I think if you follow the analogous steps, it should work for Python 2.x). I'm just documenting it here for future visitors to the page :
Pre-requisites :
wheel (Should be present by default in newer distributions)
The correct Windows build of pygraphviz (unofficial builds). On Win7 x64, I selected "pygraphviz‑$version-cp34‑none‑win_amd64.whl".
(Note the cp34 indicating the python version.)
The Graphviz installer version 2.38 (for which the above wheel is built)
Steps:
Run the Graphviz installer
Add the Graphviz\bin folder to your user or system PATH
Check: Open a command prompt and execute twopi -V. You should be able to see the Graphviz version printed onto the console.
Now go to your Python environment (e.g. by running anaconda.bat, a prompt where you can run python)
Run pip install pygraphviz‑*$version*-cp34‑none‑win_amd64.whl
You're done :) ! Run an example script to see if everything went well.
You'll find loads of install-ready packages on this site: http://www.lfd.uci.edu/~gohlke/pythonlibs/ including the ones you tried to install. I know I'm way too late with the answer but I just became a member.
You may first install "easy_install" (look at
How to use Python's "easy_install" on Windows ... it's not so easy)
then 2 packages are required: 'python-pygraph' & 'libgv-python'.

Categories

Resources