4

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
Madwand
  • 49
  • 1
  • 1
  • 4
  • Can you do `import pybind11; print(pybind11.__file__)` in a python interpreter? Since you've installed it "several different ways", I wonder which one Python is using. – 0x5453 Apr 15 '20 at 18:23
  • Does this answer your question? [Execution of Python code with -m option or not](https://stackoverflow.com/questions/22241420/execution-of-python-code-with-m-option-or-not) – compuphys Apr 15 '20 at 18:23
  • Ubuntu may have many Pythons installed - so first check if `python3 -V` and `pip3 -V` gives the same number. And then install it with `pip3`. Or use `python3.7` a `pip3.7` to work with `Python 3.7` (similar for other versions: `python3.6` and `pip3.6`, etc). OR you can install using directly python which you use to run code : `python3 -m pip install pybind11` – furas Apr 15 '20 at 18:46
  • 2
    I tested it on Linux Mint 19.3 (based on Ubuntu 18.04) `sudo pip3.7 install -U pybind11` and `python3.7 -m pybind11 --includes` and it runs without error. – furas Apr 15 '20 at 18:48
  • I have edited the question to answer the questions asked above as best I can, thanks! – Madwand Apr 15 '20 at 19:14
  • Hello, sometimes at windows there seems some libs have this error. I've fixed it by adding python scripts at user environment variables. Does linux have that? (for windows from miniconda: `c:\Users\username\AppData\Roaming\Python\Python37\Scripts`) – mrbTT Apr 15 '20 at 19:16
  • Are you using virtual environments or something similar? – AMC Apr 15 '20 at 19:27
  • No, I'm not using an environment. – Madwand Apr 15 '20 at 19:32
  • It is a common problem in *clever* environments like Linux distribs. For any reason, you end with more than one single version of Python installed in your system. And you installed pybind11 under one version and try to use it from a different one. Search all `python*` 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 use `pythonxx -m pip` instead of just `pip` to make sure to install the packages into the expected version. – Serge Ballesta Dec 21 '20 at 08:44

1 Answers1

0

try this command.

export PYTHONPATH=$PYTHONPATH:/home/xxx/pybind11
bobo
  • 9
  • 1