【问题标题】:Ubuntu 16 fatal error: Python.h: No such file or directory (Unsolved with python-devel)Ubuntu 16 致命错误:Python.h:没有这样的文件或目录(未使用 python-devel 解决)
【发布时间】:2018-02-17 14:55:57
【问题描述】:

在安装了 Anaconda 3.6 的 Ubuntu 16.04 上尝试编译 pycaffe 时,出现以下错误:

python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or directory

我尝试安装 python-devel 软件包

sudo apt-get install python3-dev 
sudo apt-get install python3.5-dev
sudo apt-get install python3.6-dev 

但即使分别尝试了其中的每一个,也会出现相同的错误。

.bashrc 中似乎添加了正确的 PATH

export PATH="home/jdevezas/anaconda/bin:$PATH"

在 Caffe 的 makefile.config 中我有

# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.

ANACONDA_HOME := /home/jdevezas/anaconda

#PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
#            $(ANACONDA_HOME)/include/python2.7 \
#            $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
 PYTHON_LIBRARIES := boost_python3 python3.5m
 PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

我也尝试过使用 Python 2.7,但没有结果。有什么建议吗?

【问题讨论】:

  • 我的解决方案是手动添加到包含路径/usr/include/python3.5

标签: python-3.x ubuntu-16.04 pycaffe


【解决方案1】:

对于python 2:

sudo apt-get install python-dev

对于python 3+:

sudo apt-get install python3-dev

然后,尝试做:

locate Python.h

并使用它在您的 makefile 中找到的目录。头文件似乎在 /usr/include/python2.7/

【讨论】:

  • 也许在安装完上面的之后他应该尝试locate Python.h 看看它的实际位置。在我的 ubuntu 工作站上,它位于 /usr/include/python2.7/Python.h
  • 为什么这个被贬低了这么多?它似乎解决了我的问题。
猜你喜欢
  • 2017-03-02
  • 2021-02-26
  • 2021-09-19
相关资源
最近更新 更多