我已经在我的Ubuntu 18.04.3机器上安装了pybind11(包括使用pip和包管理器等多种方式),但是当我尝试按照推荐的方式指定包含文件时:
python3 -m pybind11 --includes
,我遇到了这个错误:/usr/bin/python3:没有名为pybind11.__main__的模块;'pybind11'是一个包,不能直接执行
。我找到的唯一提到这个错误的地方是一个中文网页,但并没有解决问题。我该如何使pybind11正常工作?回答下面的一些问题:>>> 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__)
吗?由于你已经以“几种不同的方式”安装了它,我想知道Python正在使用哪一种。 - 0x5453python3 -V
和pip3 -V
是否给出相同的版本号。然后使用pip3
安装它。或者使用python3.7
和pip3.7
来使用Python 3.7
(其他版本类似:python3.6
和pip3.6
等)。或者您可以直接使用运行代码的 Python 安装:python3 -m pip install pybind11
。 - furassudo pip3.7 install -U pybind11
和python3.7 -m pybind11 --includes
,程序运行无误。 - furasc:\ Users \ username \ AppData \ Roaming \ Python \ Python37 \ Scripts
) - mrbTT