python synthesize midi with fluidsynth - python

I can't import fluidsynth. [Maybe there's an better module?]
I'm trying to synthesize midi from python or pygame. I can send midi events from pygame.
I'm using mingus, and it seemed pyfluidsynth would be good / easiest.
I think this means pyfluidsynth is installed, but a seperate fluidsynth was not. I don't know if it requires a 'fluidsynth' installer to work?
test.py:
import fluidsynth
print ":("
error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import fluidsynth
File "C:\Users\jake\AppData\Roaming\Python\Python27\site-packages\fluidsynth.py", line 34, in <module>
raise ImportError, "Couldn't find the FluidSynth library."
ImportError: Couldn't find the FluidSynth library.
using: python 2.7-win32

The python fluidsynth module is looking for the FluidSynth binary library file (ie fluidsynth.dll).
To get this you can download, compile and install http://sourceforge.net/projects/fluidsynth/files/fluidsynth-1.1.3/
OR
you may be able to find projects using fluidsynth (ie QSynth) which include precompiled copies of the .dll file.

Yes you need the FuildSynth lib also (dll for windows).
To make it works with:
fluid synthsynth 1.1.6
python26 (32bits)
pyFluidSynth 1.1.4
Windows
I've put everythings in the same directory (fluidsynth dll, PyFluidSynth Module, python script).
and changes the following lines in the pyFluidSynth modules (from line 30) :
# A short circuited or expression to find the FluidSynth library
# (mostly needed for Windows distributions of libfluidsynth supplied with QSynth)
# and Dynamically link the FluidSynth library
lib = find_library('fluidsynth') or find_library('libfluidsynth') or find_library('libfluidsynth-1')
if lib is None:
_fl = ctypes.cdll.LoadLibrary("./libfluidsynth")
lib = "ok";
else:
_fl = CDLL(lib)
if lib is None:
raise ImportError, "Couldn't find the FluidSynth library."
# Helper function for declaring function prototypes
It works fine with this setup.

Looking at fluidsynth.py, your guess is probably right.
You should try putting fluidsynth.dll somewhere in your system's library search path (the easiest would probably be the same directory as your script or fluidsynth.py).
I think this archive (found via google) contains the necessary win32 binary: http://svn.drdteam.org/zdoom/fluidsynth.7z

Related

py2exe "No module named 'site'" from Anaconda

I'm trying to use py2exe to build an executable on 64-bit Windows 7 with Anaconda (Python 3.4) for a project of mine that depends on a lot of libraries. Some of the more complex ones include vispy (pyopengl), PyQt4, numba, and scipy. I've been stepping through various errors to try to get a working executable, but have hit a road block with no clear way forward. Currently, the py2exe command completes, but I get the following error when running the exe:
...
from numba import jit
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\__init__.py", line
13, in <module>
from .pycc.decorators import export, exportmany
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\__init__.py",
line 12, in <module>
from .cc import CC
File "C:\Anaconda3\envs\sift_py2exe\lib\site-packages\numba\pycc\cc.py", line
4, in <module>
from distutils.command import build_ext
File "C:\Anaconda3\envs\sift_py2exe\lib\distutils\command\build_ext.py", line
17, in <module>
from site import USER_BASE
ImportError: No module named 'site'
I was able to do a small workaround by adding the C:\Anaconda3\envs\sift_py2exe\Lib directory to sys.path in my main script, but I doubt that's going to help me much later. Not to mention I had more scipy DLL issues after that.
Here are the relevant parts of my setup.py:
try:
import py2exe
from llvmlite.binding.ffi import _lib_dir, _lib_name
kwargs["data_files"] = [('.', [os.path.join(_lib_dir, _lib_name), os.path.join(_lib_dir, "MSVCP120.dll"), os.path.join(_lib_dir, "MSVCR120.dll")])]
kwargs["console"] = [{
'script': 'cspov/__main__.py',
'dest_base': "SIFT",
}]
kwargs["options"] = {'py2exe': {"includes": ["vispy.app.backends._pyqt4", "PyQt4.QtNetwork"]}}
except ImportError:
print("'py2exe' and/or 'llvmlite' not available")
I've tried adding the "Lib" directory in setup.py and then including "site", but it doesn't find the module. Any ideas? Thanks.
Side note: I'm using the Microsoft DLLs from llvmlite as a quick workaround because I couldn't get it to work in any of the normal ways.
This isn't the answer I was hoping for, but I was able to get a working executable when I switched to pyinstaller. All of the other SO questions I saw relevant to my problem had similar "solutions".

img2pdf.py "no module named Image"

Hello I am running Python 2.7 64 bit on windows 7. I've found a python script online called img2pdf.py which could be very useful to me but I can't run it. I've installed the Pillow library for win64 (from http://www.lfd.uci.edu/~gohlke/pythonlibs/)
and Image.py is present in "C:\Python27\Lib\site-packages\PIL"
I've downloaded the script to a directory containing my image, and python is on my path but when I type
python img2pdf.py myimage.j2k
at the command prompt I get an error that states
Traceback (most recent call last):
File "img2pdf.py" line 18, in <module>
import Image
ImportError: No module named Image
What have I missed?
On the Pillow library link, it is written:
Note: use from PIL import Image instead of import Image.
But when I look to the img2pdf.py script that I've found here, it is written import Image. So I guess you have to edit your img2pdf.py as specified above.
Install Python for Windows, e.g. "python-3.5.0-amd64.exe" --> C:\Python
Extract the zipped archive for img2pdf to C:\Python\Sources\img2pdf
Go to C:\Python\Scripts
Run pip.exe install ..\Sources\img2pdf
The package is now available from command line as "img2pdf.exe" in C:\Python\Scripts

Installing Audiere Module on Python 2.7 Windows 7

I have downloaded the module from sourceforge. audiere-1.9.4-win32
The unzipped folder has the following folders:
-bin
-bindings
-doc
-include
-lib
The Bindings folder includes a file called audiere.pyd and an installation instruction which says:
Into the Windows distribution of Python 2.2:
Copy audiere.dll and audiere.pyd into your Python22 directory (or
perhaps Python22/DLLs, depending on your system).
I tried copying both files to:
-python 2.7/
-python 2.7/DLL
-python 2.7 /LIb/site-packages/ directory but
import audiere
still gives a import error:
Traceback (most recent call last):
File "", line 1, in
import audiere
ImportError: DLL load failed: The specified module could not be found.
I am sure this is nothing to do with python 2.2 versus python 2.7 because people have successfully used audiere on 2.7 without any modification.
How do I install audiere on windows 7.
You can try to use pyglet. This library has the capability to play using external library called Avbin.
Simple example of how to use:
import pyglet
music = pyglet.resource.media('music.mp3')
music.play()
pyglet.app.run()
If you have some problems with avbin, put the dll in the same directory of your code and insert this two lines before "pyglet.resource.media('music.mp3')":
pyglet.lib.load_library('avbin')
pyglet.have_avbin=True

Undefined symbol TLSv1 with python+perforce

I installed the p4 library on my local archlinux machine and everything works smoothly.
I was now trying to do the same on a couple of virtual machines (with same OS also 64 bits) but can't get it running...
The installation goes well and doesn't complain, but when I try to import it I get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "P4.py", line 312, in <module>
import P4API
ImportError: /usr/lib/python2.7/site-packages/P4API.so: undefined symbol: TLSv1_method
If I look in the symbols with
nm -A /usr/lib/python2.7/site-packages/P4API.so
I can see that in fact all the SSL-related symbols are undefined (while being defined on the working one), but why on earth?
I have openssl installed and Python is installed in exactly the same way, I can't find any other library that should be useful.
Any idea?
EDIT:
apparently the only difference is that in the wrong installation of P4 P4API.so is missing librt from the "ldd" output (and librt is actually there).
Not sure how it would relate to the TLS problem, and trying to reinstall glibc and then
p4python but no luck still..
Rebuilding the P4Python against the "rt" and "ssl" libraries fixes this.
Take the P4 API off the perforce site (e.g. for Linux take this: http://filehost.perforce.com/perforce/r13.2/bin.linux26x86_64/p4api.tgz)
Take the source code of P4Python off http://public.perforce.com/guest/robert_cowham/perforce/API/python/main/p4python.zip
tar xf the P4 API archive
Unzip the p4pthon archive
Edit setup.cfg to point to the P4API directory
Edit setup.py and go to line 120 and add "ssl" and "rt" so it looks like this
else: # Assume Linux
libraries = ["client", "rpc", "supp", "ssl", "rt"] # P4API libs
extra_compile_args = ["-DOS_LINUX", "-D%s" % p4_api_ver]
Do sudo python setup.py install

Undefined Symbol in C++ When Loading a Python Shared Library

I have been trying to get a project of mine to run but I have run into trouble. After much debugging I have narrowed down the problem but have no idea how to proceed.
Some background, I am using a python script inside C++ code. This is somewhat documented on Python, and I managed to get it running very well in my basic executable. #include and a -lpython2.6 and everything was grand.
However, difficulty has arisen when running this python script from a shared library(.so). This shared library is "loaded" as a "module" by a simulation system (OpenRAVE). The system interacts with this module using a virtual method for "modules" called SendCommand. The module then starts a boost::thread, giving python its own thread, and returns to the simulation system. However, when python begins importing its modules and thus loading its dynamic libraries it fails, I assume due to the following error:
ImportError: /usr/lib/python2.6/dist-packages/numpy/core/multiarray.so: undefined symbol: _Py_ZeroStruct
I have run ldd on my executable and the shared library, there doesn't some to be a difference. I have also run nm -D on the file above, the _Py_ZeroStruct is indeed undefined. If you guys would like print outs of the commands I would be glad to supply them. Any advice would be greatly appreciated, thank you.
Here is the full python error:
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/numpy/__init__.py", line 130, in
import add_newdocs
File "/usr/lib/python2.6/dist-packages/numpy/add_newdocs.py", line 9, in
from lib import add_newdoc
File "/usr/lib/python2.6/dist-packages/numpy/lib/__init__.py", line 4, in
from type_check import *
File "/usr/lib/python2.6/dist-packages/numpy/lib/type_check.py", line 8, in
import numpy.core.numeric as _nx
File "/usr/lib/python2.6/dist-packages/numpy/core/__init__.py", line 5, in
import multiarray
ImportError: /usr/lib/python2.6/dist-packages/numpy/core/multiarray.so: undefined symbol: _Py_ZeroStruct
Traceback (most recent call last):
File "/home/constantin/workspace/OpenRAVE/src/grasp_behavior_2.py", line 3, in
from openravepy import *
File "/home/constantin/workspace/rospackages/openrave/lib/python2.6/site-packages/openravepy/__init__.py", line 35, in
openravepy_currentversion = loadlatest()
File "/home/constantin/workspace/rospackages/openrave/lib/python2.6/site-packages/openravepy/__init__.py", line 16, in loadlatest
return _loadversion('_openravepy_')
File "/home/constantin/workspace/rospackages/openrave/lib/python2.6/site-packages/openravepy/__init__.py", line 19, in _loadversion
mainpackage = __import__("openravepy", globals(), locals(), [targetname])
File "/home/constantin/workspace/rospackages/openrave/lib/python2.6/site-packages/openravepy/_openravepy_/__init__.py", line 29, in
from openravepy_int import *
ImportError: numpy.core.multiarray failed to import
I experienced the same problem with my application and solved it without linking python to the executable.
The setup is as follows:
Executable --links--> library --dynamically-loads--> plugin --loads--> python interpreter
The solution to avoid the ImportErrors was to change the parameters of dlopen, with which the plugin was loaded to RTLD_GLOBAL.
dlopen("plugin.so", RTLD_NOW | RTLD_GLOBAL)
This makes the symbols available to other things loaded afterwards, i.e. other plugins or the python interpreter.
It can, however, happen that symbol clashes occur, because a plugin later exports the same symbols.
The solution was linking the python2.6 library with my executable as well.
Even though the executable made no python calls, it needed to be linked with the python library. I assume its because my shared library doesn't pass the symbols of python library through to the executable. If anyone could explain why my executable (which loads my dynamic library at runtime, without linking) needs those symbols it would be great.
For clarification, my program model is something like:
[My Executable] -(dynamically loads)-> [My Shared Library] -(calls and links with)-> [Python shared Library]
Check your python-headers and python's runtime. It looks like you have mix of 2.5 and 2.6 versions.
there's an example in openrave that shows how to build C++ shared objects that use boost python without having the application know about it:
http://openrave.org/en/coreapihtml/orpythonbinding_8cpp-example.html
search for "python" in the cmake file here:
https://openrave.svn.sourceforge.net/svnroot/openrave/trunk/src/cppexamples/CMakeLists.txt
the relevant info is:
if( Boost_PYTHON_FOUND AND Boost_THREAD_FOUND )
find_package(PythonLibs)
if( PYTHONLIBS_FOUND OR PYTHON_LIBRARIES )
if( PYTHON_EXECUTABLE )
# get the site-packages directory
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)"
OUTPUT_VARIABLE _python_sitepackage
RESULT_VARIABLE _python_failed)
if( ${_python_failed} EQUAL 0 )
string(REGEX REPLACE "[\r\n]" "" _python_sitepackage "${_python_sitepackage}")
set(PYTHON_INCLUDE_PATH ${PYTHON_INCLUDE_PATH} ${_python_sitepackage}/numpy/core/include)
else()
message(STATUS "failed to get python site-package directory")
endif()
endif()
include_directories(${PYTHON_INCLUDE_PATH} ${OpenRAVE_INCLUDE_DIRS})
add_library(orpythonbinding SHARED orpythonbinding.cpp)
target_link_libraries(orpythonbinding ${OpenRAVE_LIBRARIES} ${PYTHON_LIBRARIES} ${Boost_PYTHON_LIBRARY} ${Boost_THREAD_LIBRARY})
set_target_properties(orpythonbinding PROPERTIES PREFIX "" COMPILE_FLAGS "${OpenRAVE_CXX_FLAGS}")
if( WIN32 )
set_target_properties(orpythonbinding PROPERTIES SUFFIX ".pyd")
endif()
endif()
endif()

Categories