【问题标题】:Failing to install Boost in Python - pyconfig.h not found无法在 Python 中安装 Boost - 找不到 pyconfig.h
【发布时间】:2017-03-16 16:13:09
【问题描述】:

我正在关注tutorial,了解如何使用 Python 进行简单的人脸识别。本教程依赖于我尝试安装的 dlib 库。但是,dlib 库依赖于 Boost 库并产生此错误:

-- Found PythonLibs: /Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib (found suitable version "3.6.0", minimum required is "3.4")
--  *****************************************************************************************************
--  To compile Boost.Python yourself download boost from boost.org and then go into the boost root folder
--  and run these commands:
--     ./bootstrap.sh --with-libraries=python
--     ./b2
--     sudo ./b2 install

当我从 Boost 下载文件夹运行 ./bootstrap.sh --with-libraries=python 时,我收到以下错误:

darwin.compile.c++ bin.v2/libs/python/build/darwin-4.2.1/release/threading-multi/numeric.o
In file included from libs/python/src/numeric.cpp:6:
In file included from ./boost/python/numeric.hpp:8:
In file included from ./boost/python/detail/prefix.hpp:13:
./boost/python/detail/wrap_python.hpp:50:11: fatal error: 'pyconfig.h' file not found
# include <pyconfig.h>
          ^
1 error generated.

    "g++"  -ftemplate-depth-128 -O3 -Wall -dynamic -gdwarf-2 -fexceptions -Wno-inline -fPIC -arch x86_64  -DBOOST_ALL_NO_LIB=1 -DBOOST_PYTHON_SOURCE -DNDEBUG  -I"." -I"/Users/mikkeld/anaconda/include/python3.5" -c -o "bin.v2/libs/python/build/darwin-4.2.1/release/threading-multi/numeric.o" "libs/python/src/numeric.cpp"

我在这里有点迷路,并且尝试过环顾四周,但没有运气。谁能发现问题所在?

【问题讨论】:

标签: python-3.x boost dlib


【解决方案1】:

感谢这个解决方案和上面的一个,我通过以下方式找到了我的 python 包含链接: 打开终端并运行: python --版本

将 3.7 替换为您当前的 Python 版本并运行:

python3.7-config --includes --libs

链接:

/Users/<username>/.pyenv/versions/3.6.7/Python.framework/Versions/3.6/include/python3.6m

并替换了我在下面C_INCLUDE_PATH 中找到的链接

编辑/etc/profile,并将以下内容附加到文件中,您应该修改指定python头的路径

C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include/python3.6m
export C_INCLUDE_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/python3.6m
export CPLUS_INCLUDE_PATH
Source /etc/profile

再次编译 它现在可以编译 boost!

【讨论】:

  • 感谢信+使用以上两个答案修改的答案
【解决方案2】:

这是给使用 Anaconda 的人的答案。

打开终端并运行:
python --version

3.7 替换为您当前的 Python 版本并运行:
python3.7-config --includes --libs

-I/home/victor/anaconda3/include/python3.7m -I/home/victor/anaconda3/include/python3.7m -lpython3.7m -lpthread -ldl -lutil -lrt -lm

现在,获取返回的第一个项目,并在您的 ~/.bashrc 上添加以下行:

export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:/home/victor/anaconda3/include/python3.7m"

获取新的 bashrc 文件
source ~/.bashrc_profile

【讨论】:

  • 我遇到了同样的错误,我在 MacOS 上按照这些说明进行操作,它似乎已经纠正了我的问题。
【解决方案3】:

我在编译boost时也遇到了这个问题,以下是我的解决方案。

  1. 安装python
  2. 编辑/etc/profile,并将以下内容附加到文件中,您应该修改指定python头文件的路径

    C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include/python3.6m

    导出 C_INCLUDE_PATH

    CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/python3.6m

    导出 CPLUS_INCLUDE_PATH

  3. 来源 /etc/profile

  4. 再次编译

它对我有用,希望你如此。

【讨论】:

    【解决方案4】:

    这是一种在 Ubuntu 18.04 上的 anaconda 的 boost 1.72 和 python 3.7 下对我有用的技术。

    • 确保您的 anaconda 环境处于活动状态(路径中的 python 正确)
    • 在您的 boost 源代码树中编辑文件 tools/build/src/tools/python.jam
    • 查找第 547 行 includes ?= $(prefix)/include/python$(version) ;
    • 替换为includes ?= $(prefix)/include/python$(version)m ;
    • ./bootstrap.sh./b2 install 像往常一样

    【讨论】:

      猜你喜欢
      • 2020-12-30
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2019-10-14
      • 2015-04-28
      • 2017-10-01
      • 1970-01-01
      • 2019-12-14
      相关资源
      最近更新 更多