"fatal error: sql.h" with unixODBC and pyodbc as a vendor app dependency
"fatal error: sql.h" with unixODBC and pyodbc as a vendor app dependency
我正在尝试将 unixODBC 添加为供应商应用程序依赖项,按照此处概述的注释:https://github.com/cloudfoundry/python-buildpack/issues/34,但我仍然遇到致命错误:
sql.h: No such file or directory.
我在下面创建了一个最小的、可验证的、完整的脚本,以方便读者重现我的问题:
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('\r\n', '\n');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('\r\n', '\n');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
这里有一个类似的问题:,但是这个问题与这个问题的不同之处在于它非常笼统,而这个问题是关于同一主题但涉及一组非常具体的构建步骤。
更新: 这是基于已接受答案的更新脚本:
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: fatal error: sql.h: No such file or directory #include
您的设置总体上看起来不错,但是在暂存期间 pip
运行 秒时,构建工具仍然无法找到库 headers。 headers 在那里,因为你将它们包含在 vendor/
目录中,但它不知道它们在那里,因为 python 模块的构建脚本不会寻找他们在那个位置。
我不知道有什么方法可以让它在 non-standard 位置查找 headers 而无需修改构建包,因为 you need to send additional arguments 到 pip
。
一些人建议设置 CPATH
and/or C_INCLUDE_PATH
环境变量,因为这些应该被 gcc
获取,但在我的测试中,这些是忽略。
最后,我认为最好的办法是使用 Conda 安装 pyodbc。以下是您的操作方式。
- 将
environment.yml
添加到项目的根目录。
- 在其中添加以下内容:
name: pyodbc-test
dependencies:
- pyodbc
- 运行
cf push
.
构建包应该 运行 在暂存期间安装 miniconda,然后使用 conda 安装依赖项,特别是 pyodbc。
希望对您有所帮助!
根据@Daniel Mikusa 的回答...
you need to send additional arguments to pip.
Pip 支持 --global-options
传递此类内容。不幸的是,选项从这里传递给 setup.py.
setup.py 有它自己的全局选项,即 build_ext
...
Options for 'build_ext' command:
--build-lib (-b) directory for compiled extension modules
--build-temp (-t) directory for temporary files (build by-products)
--plat-name (-p) platform name to cross-compile for, if supported
(default: linux-x86_64)
--inplace (-i) ignore build-lib and put compiled extensions into the
source directory alongside your pure Python modules
--include-dirs (-I) list of directories to search for header files
...
Setup.py 需要 build_ext --include-dirs <path to unixodbc/include>
据我所知,要将这些参数提供给 setup.py,每个参数必须单独添加 --global-option=
.
我刚刚经历了同样的头痛,以下对我有用。
pip install pyodbc --global-option="build_ext" --global-option="--include-dirs" --global-option="<path to unixodbc/include>"
我正在尝试将 unixODBC 添加为供应商应用程序依赖项,按照此处概述的注释:https://github.com/cloudfoundry/python-buildpack/issues/34,但我仍然遇到致命错误:
sql.h: No such file or directory.
我在下面创建了一个最小的、可验证的、完整的脚本,以方便读者重现我的问题:
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('\r\n', '\n');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('\r\n', '\n');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
这里有一个类似的问题:
更新: 这是基于已接受答案的更新脚本:
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: fatal error: sql.h: No such file or directory #include
您的设置总体上看起来不错,但是在暂存期间 pip
运行 秒时,构建工具仍然无法找到库 headers。 headers 在那里,因为你将它们包含在 vendor/
目录中,但它不知道它们在那里,因为 python 模块的构建脚本不会寻找他们在那个位置。
我不知道有什么方法可以让它在 non-standard 位置查找 headers 而无需修改构建包,因为 you need to send additional arguments 到 pip
。
一些人建议设置 CPATH
and/or C_INCLUDE_PATH
环境变量,因为这些应该被 gcc
获取,但在我的测试中,这些是忽略。
最后,我认为最好的办法是使用 Conda 安装 pyodbc。以下是您的操作方式。
- 将
environment.yml
添加到项目的根目录。 - 在其中添加以下内容:
name: pyodbc-test
dependencies:
- pyodbc
- 运行
cf push
.
构建包应该 运行 在暂存期间安装 miniconda,然后使用 conda 安装依赖项,特别是 pyodbc。
希望对您有所帮助!
根据@Daniel Mikusa 的回答...
you need to send additional arguments to pip.
Pip 支持 --global-options
传递此类内容。不幸的是,选项从这里传递给 setup.py.
setup.py 有它自己的全局选项,即 build_ext
...
Options for 'build_ext' command:
--build-lib (-b) directory for compiled extension modules
--build-temp (-t) directory for temporary files (build by-products)
--plat-name (-p) platform name to cross-compile for, if supported
(default: linux-x86_64)
--inplace (-i) ignore build-lib and put compiled extensions into the
source directory alongside your pure Python modules
--include-dirs (-I) list of directories to search for header files
...
Setup.py 需要 build_ext --include-dirs <path to unixodbc/include>
据我所知,要将这些参数提供给 setup.py,每个参数必须单独添加 --global-option=
.
我刚刚经历了同样的头痛,以下对我有用。
pip install pyodbc --global-option="build_ext" --global-option="--include-dirs" --global-option="<path to unixodbc/include>"