DDMAL / libmei

C++ library and Python bindings for the Music Encoding Initiative format
http://music-encoding.org
Other
63 stars 23 forks source link

Building Python Bindings: Python.h not found in src/_libmei.cpp #92

Closed tobiasschweizer closed 9 years ago

tobiasschweizer commented 9 years ago

Hi,

I have just tried to build the Python bindings after succesfully having compiled and installed libmei.

I followed the instructions on https://github.com/DDMAL/libmei/wiki/Installing-the-Python-bindings

:~/gitreps/libmei/python$ python setup.py build
running build
running build_py
running egg_info
writing pymei.egg-info/PKG-INFO
writing top-level names to pymei.egg-info/top_level.txt
writing dependency_links to pymei.egg-info/dependency_links.txt
reading manifest file 'pymei.egg-info/SOURCES.txt'
writing manifest file 'pymei.egg-info/SOURCES.txt'
running build_ext
building 'pymei/_libmei' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_libmei.cpp -o build/temp.linux-x86_64-2.7/src/_libmei.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
src/_libmei.cpp:24:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

It doesn't find Python.h. Where would that file be located?

I use Python 2.7.

Thx.

bencornu commented 9 years ago

Hi, We have the same kind of problem. On what OS are you testing ?

python2.7 setup.py build
running build
running build_py
running egg_info
writing pymei.egg-info/PKG-INFO
writing top-level names to pymei.egg-info/top_level.txt
writing dependency_links to pymei.egg-info/dependency_links.txt
reading manifest file 'pymei.egg-info/SOURCES.txt'
writing manifest file 'pymei.egg-info/SOURCES.txt'
running build_ext
building 'pymei/_libmei' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c src/_libmei.cpp -o build/temp.linux-x86_64-2.7/src/_libmei.o
cc1plus: attention : l'option de la ligne de commande "-Wstrict-prototypes" est valide pour Ada/C/ObjC mais pas pour C++
src/_libmei.cpp:32:28: erreur: boost/python.hpp : Aucun fichier ou dossier de ce type
src/_libmei.cpp:33:34: erreur: boost/python/tuple.hpp : Aucun fichier ou dossier de ce type
src/_libmei.cpp:34:37: erreur: boost/python/iterator.hpp : Aucun fichier ou dossier de ce type
src/_libmei.cpp:35:65: erreur: boost/python/suite/indexing/vector_indexing_suite.hpp : Aucun fichier ou dossier de ce type
src/_libmei.cpp:36:49: erreur: boost/python/exception_translator.hpp : Aucun fichier ou dossier de ce type
src/_libmei.cpp:43: erreur: ‘boost’ has not been declared
src/_libmei.cpp:43: erreur: ‘python’ is not a namespace-name
src/_libmei.cpp:43: erreur: expected namespace-name before ‘;’ token
src/_libmei.cpp:132: erreur: ‘converter’ has not been declared
src/_libmei.cpp:132: erreur: expected ‘,’ or ‘...’ before ‘*’ token
src/_libmei.cpp: In constructor ‘VectorFromList<T>::VectorFromList()’:
src/_libmei.cpp:120: erreur: ‘converter’ has not been declared
src/_libmei.cpp:120: erreur: ‘type_id’ was not declared in this scope
src/_libmei.cpp:120: erreur: expected primary-expression before ‘>’ token
src/_libmei.cpp:120: erreur: expected primary-expression before ‘)’ token
src/_libmei.cpp: In static member function ‘static void VectorFromList<T>::construct(PyObject*, int)’:
src/_libmei.cpp:134: erreur: ‘converter’ has not been declared
src/_libmei.cpp:134: erreur: expected primary-expression before ‘>’ token
src/_libmei.cpp:134: erreur: expected primary-expression before ‘)’ token
src/_libmei.cpp:134: erreur: ‘data’ was not declared in this scope
src/_libmei.cpp:148: erreur: ‘extract’ was not declared in this scope
src/_libmei.cpp:148: erreur: expected primary-expression before ‘*’ token
src/_libmei.cpp:148: erreur: expected primary-expression before ‘>’ token
src/_libmei.cpp: At global scope:
src/_libmei.cpp:156: erreur: expected constructor, destructor, or type conversion before ‘(’ token
error: command 'gcc' failed with exit status 1
tobiasschweizer commented 9 years ago

Sorry, I should have provided that information:

Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:    14.04
Codename:   trusty

Seems that I hadn't installed all the necessary libraries for python on my system:

Now I am still missing boost_python-mt-py27

~/gitreps/libmei/python$ python setup.py build
running build
running build_py
running egg_info
writing pymei.egg-info/PKG-INFO
writing top-level names to pymei.egg-info/top_level.txt
writing dependency_links to pymei.egg-info/dependency_links.txt
reading manifest file 'pymei.egg-info/SOURCES.txt'
writing manifest file 'pymei.egg-info/SOURCES.txt'
running build_ext
building 'pymei/_libmei' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_libmei.cpp -o build/temp.linux-x86_64-2.7/src/_libmei.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/_libmei.o -L/usr/local/lib -Wl,-R/usr/local/lib -lboost_python-mt-py27 -lmei -lboost_python-py27 -o build/lib.linux-x86_64-2.7/pymei/_libmei.so -L/usr/local/lib -L/usr/lib
/usr/bin/ld: cannot find -lboost_python-mt-py27
collect2: error: ld returned 1 exit status
error: command 'c++' failed with exit status 1
tobiasschweizer commented 9 years ago

-> https://github.com/DDMAL/libmei/issues/81

In setup.py, I just removed "-mt" and it compiled fine.

tobiasschweizer commented 9 years ago

What is this permission/location stuff?

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymei
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning: /home/tobi/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
  warnings.warn(msg, UserWarning)
tobiasschweizer commented 9 years ago

@ahankinson Could you please update the instructions on https://github.com/DDMAL/libmei/wiki/Installing-the-Python-bindings according to the links I provided with the dependencies that have to be met?

ahankinson commented 9 years ago

@ifkarp could you please have a look at this issue? Thanks.

ifkarp commented 9 years ago

@tobiasschweizer Which libraries did you install and which commands did you use to install them to get libmei to compile?

tobiasschweizer commented 9 years ago
sudo apt-get install build-essential python-dev python-setuptools libboost-python-dev libboost-thread-dev

And this is my modified setup.py:

from setuptools import find_packages
from distutils.core import setup, Extension
import sys
import os

longdesc = """ Python Bindings for LibMEI. """

if sys.platform == "darwin":
    link_args = ["-framework", "mei"]
    libraries = ["boost_python"]
    library_dirs = []
    runtime_library_dirs = []
    include_dirs = []
elif sys.platform == "freebsd8":
    libraries = ['boost_python', 'mei']
    library_dirs = ['/usr/local/lib']
    runtime_library_dirs = ['/usr/local/lib']
    include_dirs = ['/usr/local/include']
    link_args = ["-L/usr/local/lib", "-L/usr/lib"]
else:
    if sys.platform == "linux2":
        import platform
        if platform.linux_distribution()[0] == "Ubuntu":
            # Ubuntu names its boost libraries a bit differently.
            # figure out what version of python
            ver = platform.python_version_tuple()
            libraries = ["boost_python-py{0}{1}".format(ver[0], ver[1]), "mei", "boost_python-py{0}{1}".format(ver[0], ver[1])]
            library_dirs = ["/usr/local/lib", "/usr/lib"]
            runtime_library_dirs = ["/usr/local/lib", "/usr/lib"]
            include_dirs = []
        else:
            libraries = ["boost_python", "mei"]
            library_dirs = ["/usr/local/lib", "/usr/lib"]
            runtime_library_dirs = ["/usr/local/lib", "/usr/lib"]
            include_dirs = []
    link_args = ["-L/usr/local/lib", "-L/usr/lib"]

setup(
    name = 'pymei',
    long_description = longdesc,
    version = '2.0',
    url = "http://github.com/DDMAL/libmei",
    include_package_data=True,
    packages=find_packages(),
    ext_modules = [
        Extension(os.path.join("pymei", "_libmei"),
            [os.path.join("src","_libmei.cpp")],
            libraries=libraries,
            extra_link_args=link_args,
            library_dirs=library_dirs,
            include_dirs=include_dirs,
            runtime_library_dirs=runtime_library_dirs
        ),
        Extension(os.path.join("pymei","_libmei_exceptions"),
            [os.path.join("src","_libmei_exceptions.cpp")],
            libraries=libraries,
            extra_link_args=link_args,
            library_dirs=library_dirs,
            include_dirs=include_dirs,
            runtime_library_dirs=runtime_library_dirs
        ),
    ],
    test_suite="pymei_testsuite"
)
ifkarp commented 9 years ago

Perfect, thanks a lot! I'll update the documentation right away.

As for the issue with permission, you should be able to remove the warning by changing the permission of .python-eggs to no longer allow groups/others to write to it with the following command:

chmod g-wx,o-wx ~/.python-eggs

http://stackoverflow.com/questions/17626694/remove-python-userwarning

ifkarp commented 9 years ago

I've updated the wiki along with the temporary fix for issue #81 , if there are any other issues related to this thread I'll reopen it.

As soon as I have a more permanent fix I'll be closing that issue as well