"pip install SQLAlchemy"导致"致命错误:Python.h:没有这样的文件或目录"

Pat*_*awa 13 python sqlalchemy

调用

pip install SQLAlchemy
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

lib/sqlalchemy/cextension/processors.c:10:20: fatal error: Python.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

据我所知,我有正确的Python版本(2.7.3)和操作系统(Ubuntu 12.04)(见下文).我做错了吗?

安装确实有效

pip install --global-option='--without-cextensions' SQLAlchemy"
Run Code Online (Sandbox Code Playgroud)

但我想要C扩展.

全输出:

root@mycomputer:/# pip install SQLAlchemy
Downloading/unpacking SQLAlchemy
  Downloading SQLAlchemy-0.8.3.tar.gz (3.9Mb): 3.9Mb downloaded
  Running setup.py egg_info for package SQLAlchemy

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc/build/output'
Installing collected packages: SQLAlchemy
  Running setup.py install for SQLAlchemy
    building 'sqlalchemy.cprocessors' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c lib/sqlalchemy/cextension/processors.c -o build/temp.linux-x86_64-2.7/lib/sqlalchemy/cextension/processors.o
    lib/sqlalchemy/cextension/processors.c:10:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    ***************************************************************************
    command 'gcc' failed with exit status 1
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Failure information, if any, is above.
    Retrying the build without the C extension now.
    ***************************************************************************

    warning: no files found matching '*.jpg' under directory 'doc'
    no previously-included directories found matching 'doc/build/output'
    ***************************************************************************
    WARNING: The C extension could not be compiled, speedups are not enabled.
    Plain-Python build succeeded.
    ***************************************************************************
Successfully installed SQLAlchemy
Cleaning up...
root@mycomputer:/#
Run Code Online (Sandbox Code Playgroud)

Python版本:

root@mycomputer:/#python -V
Python 2.7.3
root@mycomputer:/#
Run Code Online (Sandbox Code Playgroud)

Ubuntu版本:

root@mycomputer:/#cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
root@mycomputer:/#
Run Code Online (Sandbox Code Playgroud)

Mat*_*DMo 22

您需要python-dev为您的Python版本安装(或类似名称)包.它包括编译C扩展所需的所有头文件.(遗憾的是)这些文件不包含在默认python包中.

对于Ubuntu,命令是

sudo apt-get install python-dev
Run Code Online (Sandbox Code Playgroud)

要么

sudo apt-get install python3-dev
Run Code Online (Sandbox Code Playgroud)

取决于您使用的版本.