Python2.7 - 在 CentOS 6.3 上 pip install pymssql 失败

Python2.7 - pip install pymssql fails on CentOS 6.3

我正在尝试在 CentOS 机器上为 Python 安装 pymssql,但它在我身上总是失败。

我已经安装了以下软件:

freetds-devel

python-devel

这似乎是我在搜索中不断遇到的修复方法,但是我已经安装了这两个,但我仍然收到以下错误:

pip install pymssql
Collecting pymssql
/usr/local/lib/python2.7/site-packages/pip-6.1.1-py2.7.egg/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: 
  Using cached pymssql-2.1.1.tar.gz
Installing collected packages: pymssql
  Running setup.py install for pymssql
    Complete output from command /usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-oU7MKZ/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-PE9Gxh-record/install-record.txt --single-version-externally-managed --compile:
    setup.py: platform.system() => 'Linux'
    setup.py: platform.architecture() => ('64bit', 'ELF')
    setup.py: platform.linux_distribution() => ('Red Hat Enterprise Linux Server', '6.3', '*******')
    setup.py: platform.libc_ver() => ('glibc', '2.3')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']
    running install
    running build
    running build_ext
    building '_mssql' extension
    creating build
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/local/include/python2.7 -c _mssql.c -o build/temp.linux-x86_64-2.7/_mssql.o -DMSDBLIB
    _mssql.c:314:22: error: sqlfront.h: No such file or directory
    In file included from _mssql.c:316:
    cpp_helpers.h:34:19: error: sybdb.h: No such file or directory
    _mssql.c:532: error: expected specifier-qualifier-list before ‘BYTE’
    _mssql.c:683: error: expected specifier-qualifier-list before ‘DBPROCESS’

    .............[Lots of errors removed from here]

    :22123: error: ‘SYBVARBINARY’ undeclared (first use in this function)
    _mssql.c:22135: error: ‘SYBVARCHAR’ undeclared (first use in this function)
    _mssql.c: At top level:
    _mssql.c:23607: error: expected ‘)’ before ‘val’
    _mssql.c:23689: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__Pyx_PyInt_from_py_DBINT’
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
    Command "/usr/local/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-oU7MKZ/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-PE9Gxh-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-oU7MKZ/pymssql

所以我在日志中看到这个错误:

_mssql.c:314:22: error: sqlfront.h: No such file or directory In file included from _mssql.c:316:

根据搜索,我需要安装 freetds-devel and/or python-devel 但我已经安装了。

我也注意到这一行:

setup.py: Not using bundled FreeTDS

我是基于 Linux 的操作的新手,所以我不确定这是否意味着它根本不使用 FreeTDS,或者它是否仅使用我下载的版本而不是捆绑版本或其他东西?这是否表明我下载的 freetds-devel 没有被正确使用?如果是这样,我怎样才能 setup.py 使用我下载的 freetds-devel?

如果 freetds-devel 不是问题,那么我还缺少其他安装 pymssql 的东西吗?

编辑:更多信息

当我运行以下查找命令时:

sudo find / -name "sqlfront.h"

它抱怨的文件在这里找到:

/usr/include/freetds/sqlfront.h

那么是我的 FreeTDS 安装出错了还是出了什么问题?

你需要那些 headers,这就是它失败的原因。

你能做一个吗

sudo find / -name "sqlfront.h"

以下是可能的答案:

Error while install pymssql in centos 7

做一个:

百胜安装freetds-devel

安装后重试。

你没有提到你使用的是哪个版本的 CentOS。既然你说 Python 2.7,我将假设 CentOS 7。如果你使用 CentOS 6 并使用本地构建的 Python,请更新你的问题。

无论如何,在我的 CentOS 7 系统上:

# rpm -q centos-release
centos-release-7-1.1503.el7.centos.2.8.x86_64

安装 EPEL 存储库后:

# yum -y install epel-release

然后安装要求:

# yum -y install gcc python-pip python-devel freetds-devel

我成功了pip install pymssql:

# pip install pymssql
Downloading/unpacking pymssql
  Downloading pymssql-2.1.1.tar.gz (2.4MB): 2.4MB downloaded
  Running setup.py (path:/tmp/pip-build-iWrHta/pymssql/setup.py) egg_info for package pymssql
    setup.py: platform.system() => 'Linux'
    setup.py: platform.architecture() => ('64bit', 'ELF')
    setup.py: platform.linux_distribution() => ('CentOS Linux', '7.1.1503', 'Core')
    setup.py: platform.libc_ver() => ('glibc', '2.2.5')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']

    Installed /tmp/pip-build-iWrHta/pymssql/setuptools_git-1.1-py2.7.egg

Installing collected packages: pymssql
  Running setup.py install for pymssql
    setup.py: platform.system() => 'Linux'
    setup.py: platform.architecture() => ('64bit', 'ELF')
    setup.py: platform.linux_distribution() => ('CentOS Linux', '7.1.1503', 'Core')
    setup.py: platform.libc_ver() => ('glibc', '2.2.5')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']
    building '_mssql' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c _mssql.c -o build/temp.linux-x86_64-2.7/_mssql.o -DMSDBLIB
    gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/_mssql.o -L/usr/local/lib -L/usr/lib64 -lsybdb -lrt -lpython2.7 -o build/lib.linux-x86_64-2.7/_mssql.so
    building 'pymssql' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c pymssql.c -o build/temp.linux-x86_64-2.7/pymssql.o -DMSDBLIB
    gcc -pthread -shared -Wl,-z,relro build/temp.linux-x86_64-2.7/pymssql.o -L/usr/local/lib -L/usr/lib64 -lsybdb -lrt -lpython2.7 -o build/lib.linux-x86_64-2.7/pymssql.so

Successfully installed pymssql
Cleaning up...

看起来文件与 setup.py 配置所在的位置不同。

为了解决这个问题,我将文件从 /usr/include/ 复制到 usr/local/include

然后运行

pip install pymssql

成功了。

我引用了这个答案 -

我认为更改为 setup.py 使用的路径会更好,但我无法找到成功执行此操作的方法。

将包含路径添加到 sqlfront.h 所在的位置:

export C_INCLUDE_PATH=/usr/include/freetds/

然后再次 pip install pymssql。

我有同样的错误。您必须安装 freetds-devel。

作为所有回复的结果。

要在centos 6.3、6.5上安装pymssql需要:

yum install freetds freetds-devel python-devel

将文件从 /usr/include/ 移动到 /usr/local/include 和 运行

pip install pymssql

pip download pymssql
tar xzf pymsql*tar.gz
cd pymssql*

编辑 setup.py 并将 usr_local 从“/usr/local”更改为 'usr' 和 运行:

python setup.py install