Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install fails: No module named 'pybind11' #32

Closed
DomHudson opened this issue May 7, 2018 · 5 comments
Closed

Install fails: No module named 'pybind11' #32

DomHudson opened this issue May 7, 2018 · 5 comments

Comments

@DomHudson
Copy link

Summary

Unfortunately the setup process has started to fail. Unsure what the cause of this is, it could to do with how setup.py imports pybind11.

System

Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0] on linux
Name: pip
Version: 10.0.1
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04 LTS
Release:	18.04
Codename:	bionic

$ pip install git+https://github.com/pybind/python_example

Collecting git+https://github.com/pybind/python_example
Cloning https://github.com/pybind/python_example to /tmp/pip-req-build-_2f417pj
Collecting pybind11>=2.2 (from python-example==0.0.1)
Using cached https://files.pythonhosted.org/packages/12/90/0f92a575dc60c8fba6d0c91d6b45abdb1058da9ebed40400cbcfad2ac0a7/pybind11-2.2.3-py2.py3-none-any.whl
Building wheels for collected packages: python-example
Running setup.py bdist_wheel for python-example ... error
Complete output from command /home/dom/env/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-req-build-_2f417pj/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-f4j10o78 --python-tag cp36:
running bdist_wheel
running build
running build_ext
creating tmp
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-EKG1lX/python3.6-3.6.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/dom/env/include/python3.6m -c /tmp/tmpfcwb_k_e.cpp -o tmp/tmpfcwb_k_e.o -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-EKG1lX/python3.6-3.6.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/dom/env/include/python3.6m -c /tmp/tmpggfsh938.cpp -o tmp/tmpggfsh938.o -fvisibility=hidden
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
building 'python_example' extension
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-req-build-_2f417pj/setup.py", line 103, in
zip_safe=False,
File "/home/dom/env/lib/python3.6/site-packages/setuptools/init.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/dom/env/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 202, in run
self.run_command('build')
File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3.6/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/dom/env/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 78, in run
_build_ext.run(self)
File "/usr/lib/python3.6/distutils/command/build_ext.py", line 339, in run
self.build_extensions()
File "/tmp/pip-req-build-_2f417pj/setup.py", line 90, in build_extensions
build_ext.build_extensions(self)
File "/usr/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/usr/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "/home/dom/env/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 199, in build_extension
_build_ext.build_extension(self, ext)
File "/usr/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
depends=ext.depends)
File "/usr/lib/python3.6/distutils/ccompiler.py", line 566, in compile
depends, extra_postargs)
File "/usr/lib/python3.6/distutils/ccompiler.py", line 341, in _setup_compile
pp_opts = gen_preprocess_options(macros, incdirs)
File "/usr/lib/python3.6/distutils/ccompiler.py", line 1075, in gen_preprocess_options
pp_opts.append("-I%s" % dir)
File "/tmp/pip-req-build-_2f417pj/setup.py", line 20, in str
import pybind11
ModuleNotFoundError: No module named 'pybind11'


Failed building wheel for python-example
Running setup.py clean for python-example
Failed to build python-example
Installing collected packages: pybind11, python-example
Running setup.py install for python-example ... done
Successfully installed pybind11-2.2.3 python-example-0.0.1

@DomHudson
Copy link
Author

Changing the get_pybind_include class to this in setup.py seems to fix the issue. Unsure why this has suddenly cropped up though.

class get_pybind_include(object):
    """Helper class to determine the pybind11 include path

    The purpose of this class is to postpone importing pybind11
    until it is actually installed, so that the ``get_include()``
    method can be invoked. """

    def __init__(self, user=False):
        try:
            import pybind11
        except ImportError:
            if subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11']):
                raise RuntimeError('pybind11 install failed.')

        self.user = user

    def __str__(self):
        import pybind11
        return pybind11.get_include(self.user)

DomHudson pushed a commit to ThoughtRiver/fastText that referenced this issue May 8, 2018
DomHudson pushed a commit to ThoughtRiver/fastText that referenced this issue May 8, 2018
@nschloe
Copy link

nschloe commented Jul 1, 2018

I'm getting the same error with fastfunc.

@Shubhammawa
Copy link

Changing the get_pybind_include class to this in setup.py seems to fix the issue. Unsure why this has suddenly cropped up though.

class get_pybind_include(object):
    """Helper class to determine the pybind11 include path

    The purpose of this class is to postpone importing pybind11
    until it is actually installed, so that the ``get_include()``
    method can be invoked. """

    def __init__(self, user=False):
        try:
            import pybind11
        except ImportError:
            if subprocess.call([sys.executable, '-m', 'pip', 'install', 'pybind11']):
                raise RuntimeError('pybind11 install failed.')

        self.user = user

    def __str__(self):
        import pybind11
        return pybind11.get_include(self.user)

Just wanted to add a minor thing that we need to import subprocess for this to work.
The installation after this fix seemed to work fine apart from the many warnings it generated (comparisons between signed and unsigned integer expressions, and -Wstrict-prototpes is valid for C but not C++).

@swillner
Copy link
Contributor

swillner commented Apr 3, 2019

I had the same problem in a similar project and adding setup_requires=['pybind11>=2.2'] to the setup() call in setup.py fixed it.

@wjakob
Copy link
Member

wjakob commented Jun 25, 2019

Should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants