致命错误:使用unixODBC和pyodbc作为供应商应用程序依赖项的sql.h& [英] "fatal error: sql.h" with unixODBC and pyodbc as a vendor app dependency

查看:0
本文介绍了致命错误:使用unixODBC和pyodbc作为供应商应用程序依赖项的sql.h&的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将unixODBC添加为供应商应用程序依赖项,如下所示:https://github.com/cloudfoundry/python-buildpack/issues/34,但我仍然收到致命错误:

sql.h:没有这样的文件或目录。

我在下面创建了一个最小的、可验证的、完整的脚本,以方便读者复制我的问题:

mkdir new_app
cd new_app

cat <<EOF>requirements.txt
pyodbc==4.0.17
EOF

cat <<EOF>manifest.yml
applications:
 - name: pyodbc-test
   memory: 128M
EOF

cat <<EOF>.profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/vendor/unixodbc/lib
EOF

sudo docker run -it --rm -v ${PWD}:/app cloudfoundry/cflinuxfs2 bash -c 
   "wget ftp://ftp.unixodbc.org/pub/unixODBC/unixODBC-2.3.4.tar.gz;  tar xzf unixODBC-2.3.4.tar.gz; cd unixODBC-2.3.4;  ./configure --prefix=/app/vendor/unixodbc; make; make install;"

后跟:

sudo chown -R ${USER}:${USER} vendor/
pip3 download -r requirements.txt -d vendor/
cf push 

cf推送输出:

...
-------> Buildpack version 1.5.15
 !     Warning: Your application is missing a Procfile. This file tells Cloud Foundry how to run your application.
 !     Learn more: https://docs.cloudfoundry.org/buildpacks/prod-server.html#procfile
-----> Installing python-2.7.13
Downloaded [file:///tmp/buildpack/dependencies/https___buildpacks.cloudfoundry.org_dependencies_python_python-2.7.13-linux-x64.tgz]
     $ pip install -r requirements.txt
       Collecting pyodbc==4.0.17 (from -r requirements.txt (line 1))
       Installing collected packages: pyodbc
         Running setup.py install for pyodbc: started
           Running setup.py install for pyodbc: finished with status 'error'
           Complete output from command /app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-sxxn23/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('
', '
');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-lRnuMu-record/install-record.txt --single-version-externally-managed --compile:
           running build
           running build_ext
           building 'pyodbc' extension
           creating build/temp.linux-x86_64-2.7
           creating build/temp.linux-x86_64-2.7/src
           gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=4.0.17 -I/app/.heroku/python/include/python2.7 -c src/errors.cpp -o build/temp.linux-x86_64-2.7/src/errors.o -Wno-write-strings
           cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
           In file included from src/errors.cpp:2:0:
           src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory
            #include <sql.h>
                            ^
           compilation terminated.

           ----------------------------------------
           running install
           creating build
           error: command 'gcc' failed with exit status 1
Command "/app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-sxxn23/pyodbc/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('
', '
');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-lRnuMu-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-sxxn23/pyodbc/
Failed to compile droplet
Exit status 223
Staging failed: Exited with status 223
Destroying container
Successfully destroyed container

这里有一个类似的问题:pyodbc install on IBM Bluemix server error,但该问题与此问题不同,因为它非常通用,而此问题与同一主题有关,但涉及一组非常特定的构建步骤。


更新:以下是基于接受答案的更新脚本:

mkdir new_app
cd new_app

cat <<EOF>environment.yml
name: pyodbc-test
dependencies:
- pyodbc
EOF

cat <<EOF>manifest.yml
applications:
 - name: pyodbc-test
   memory: 128M
EOF

cf push 

推荐答案

src/pyodbc.h:56:17:致命错误:sql.h:没有这样的文件或目录#INCLUDE

您的设置通常看起来没有问题,但是当pip在试运行期间运行时,构建工具仍然无法找到库头文件。标头在那里是因为您将它们包含在vendor/目录中,但它不知道它们在那里,因为python模块的构建脚本不会在该位置查找它们。

我不知道有什么方法可以让它在不修改生成包的情况下在非标准位置查找标头,因为you need to send additional argumentspip

一些人建议设置CPATH和/或C_INCLUDE_PATH环境变量,因为这些变量应该由gcc选取,但在我的测试中,这些变量被忽略。

最后,我认为您最好的选择是使用conda来安装pyodbc。以下是你将如何去做。

  1. environment.yml添加到项目的根目录。
  2. 在其中添加以下内容:
name: pyodbc-test
dependencies:
- pyodbc
  1. 运行cf push

生成包应在暂存期间运行,安装minconda,然后安装您与conda的依赖项,特别是pyodbc。

希望能有所帮助!

这篇关于致命错误:使用unixODBC和pyodbc作为供应商应用程序依赖项的sql.h&amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆