安装了pybind11后出现"No module named pybind11"错误

4
我已经在我的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

你能在Python解释器中执行 import pybind11; print(pybind11.__file__) 吗?由于你已经以“几种不同的方式”安装了它,我想知道Python正在使用哪一种。 - 0x5453
Ubuntu 可能安装了多个 Python 版本 - 因此首先检查 python3 -Vpip3 -V 是否给出相同的版本号。然后使用 pip3 安装它。或者使用 python3.7pip3.7 来使用 Python 3.7(其他版本类似:python3.6pip3.6 等)。或者您可以直接使用运行代码的 Python 安装:python3 -m pip install pybind11 - furas
2
我在Linux Mint 19.3上进行了测试(基于Ubuntu 18.04),使用命令sudo pip3.7 install -U pybind11python3.7 -m pybind11 --includes,程序运行无误。 - furas
我已经尽力编辑了问题,以回答上述提出的问题,谢谢! - Madwand
你好,有时在Windows上似乎会出现某些库的错误。我通过将Python脚本添加到用户环境变量来解决这个问题。Linux有这个吗?(对于来自Miniconda的Windows为:c:\ Users \ username \ AppData \ Roaming \ Python \ Python37 \ Scripts - mrbTT
显示剩余4条评论
2个回答

0
pybind11已经安装好了。在安装Fasttext时,找不到pybind11,直到我运行了以下命令: pip install wheel setuptools pip --upgrade

0

尝试使用这个命令。

export PYTHONPATH=$PYTHONPATH:/home/xxx/pybind11

这对我没有帮助。 - Nairum

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接