【问题标题】:Python2.7 - pip install pymssql fails on CentOS 6.3Python2.7 - 在 CentOS 6.3 上 pip install pymssql 失败
【发布时间】:2015-07-18 12:57:15
【问题描述】:

我正在尝试在 CentOS 机器上安装 Python 的 pymssql,但它一直在我身上失败。

我已经安装了以下:

freetds-开发

python开发

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

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:错误:sqlfront.h:在 _mssql.c:316 包含的文件中没有这样的文件或目录:

搜索结果表明我需要安装 freetds-devel 和/或 python-devel 但我已经安装了。

我也注意到这一行:

setup.py:不使用捆绑的 FreeTDS

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

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

编辑:更多信息

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

sudo find / -name "sqlfront.h"

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

/usr/include/freetds/sqlfront.h

难道只是我的 FreeTDS 安装搞砸了还是出了什么问题?

【问题讨论】:

    标签: python centos pip freetds pymssql


    【解决方案1】:

    作为所有响应的结果。

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

    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
    

    【讨论】:

    • 在 AWS Linux (Centos) 上运行我只需要安装 yum 和 pip,不需要移动文件
    【解决方案2】:

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

    【讨论】:

    • 问题的发帖人已经说明他们安装了freetds-devel。
    【解决方案3】:

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

    export C_INCLUDE_PATH=/usr/include/freetds/
    

    然后再次 pip install pymssql。

    【讨论】:

      【解决方案4】:

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

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

      然后运行

      pip 安装 pymssql

      成功了。

      我引用了这个答案 - Installing pymssql in Centos 6.6 64-bit

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

      【讨论】:

        【解决方案5】:

        您没有提及您使用的是哪个版本的 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 installpymssql:

        # 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...
        

        【讨论】:

        • 请注意,完全相同的过程适用于 CentOS 6 上的 Python 2.6。
        • 我正在使用 CentOS 6.3 - 当我运行您的第一个命令时,我得到 - 未安装包 centos-release - 我得到的第二个 - 没有可用的包 epel-release。 - 除了我收到此消息的 python-pip 之外,第三个 every 已经安装 - 没有可用的包 python-pip。 - 最后尝试安装 pymssql 导致我的问题出现错误
        • 请注意,它上面有 Python 2.6,但我必须使用 altinstall 安装 python 2.7 才能让 pip 工作。
        【解决方案6】:

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

        你可以做一个

        sudo find / -name "sqlfront.h"

        这是可能的答案:

        Error while install pymssql in centos 7

        做一个:

        yum install freetds-devel

        安装后重试。

        【讨论】:

        • 当我运行 find 命令时,它会在此处找到文件 - /usr/include/freetds/sqlfront.h - 我已经安装了 freetds-devel
        猜你喜欢
        • 2016-12-08
        • 2018-12-17
        • 2021-09-25
        • 1970-01-01
        • 2017-05-18
        • 2022-01-16
        • 1970-01-01
        • 2021-05-13
        • 2021-06-28
        相关资源
        最近更新 更多