I have installed pybind11 (several different ways, including pip and the package manager) on my Ubuntu 18.04.3 machine, but when I try to specify include files the recommended way:
python3 -m pybind11 --includes
I get this error:
/usr/bin/python3: No module named pybind11.__main__; 'pybind11' is a package and cannot be directly executed
The only place I've found this error mentioned is a Chinese web page which wasn't helpful in resolving the problem. How do I get pybind11 to work?
To answer some of the questions below:
>>> import pybind11; print(pybind11.__file__)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pybind11' has no attribute '__file__'
> python3 -m pip install pybind11
WARNING: The directory '/home/<username>/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pybind11 in /usr/local/lib/python3.6/dist-packages (2.5.0)
> sudo pip3 -V
pip 20.0.2 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
> python3 -V
Python 3.6.8
import pybind11; print(pybind11.__file__)
in a python interpreter? Since you've installed it "several different ways", I wonder which one Python is using. – Millisecondpython3 -V
andpip3 -V
gives the same number. And then install it withpip3
. Or usepython3.7
apip3.7
to work withPython 3.7
(similar for other versions:python3.6
andpip3.6
, etc). OR you can install using directly python which you use to run code :python3 -m pip install pybind11
– Salvidorsudo pip3.7 install -U pybind11
andpython3.7 -m pybind11 --includes
and it runs without error. – Salvidorc:\Users\username\AppData\Roaming\Python\Python37\Scripts
) – Qadipython*
files under /bin, /usr/bin/, /usr/local/bin. If you have more than one, it will be a hint that you fell in this problem. The key when it happens is to use the full name of the python version that you want to use, and usepythonxx -m pip
instead of justpip
to make sure to install the packages into the expected version. – Supernational