1

我有一个基于这个 docker 文件构建的 Docker Image 。 docker 映像带有一个 Ubuntu 14.04 的 Vagrant VM,我在 OSX 10.11.6 中运行它。Microsoft SQL Server 位于 aws-ec2 实例中。由于我的程序是用 Python 编写的,因此我尝试了 2 个用于连接数据库的 python 库,但每个库都以相同的方式失败。以下是迄今为止发生的情况的概述:

  • apk add freetds-dev因为需要安装 FreeTDS 才能与 Microsoft SQL 数据库交互。
  • pip install pymssql并且pip install pyobdc都失败并显示相同的错误消息:

{ bash-4.3# pip install pymssql

Collecting pymssql
  Using cached pymssql-2.1.3.tar.gz
    Complete output from command python setup.py egg_info:
    setup.py: platform.system() => 'Linux'
        Download error on     https://pypi.python.org/simple/setuptools_git/:         [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found!
    Download error on https://pypi.python.org/simple/setuptools-git/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found!
    Couldn't find index page for 'setuptools_git' (maybe misspelled?)
    Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) -- Some packages may not be found!
    No local packages or download links found for setuptools-git
    setup.py: platform.architecture() => ('64bit', '')
    setup.py: platform.linux_distribution() => ('', '', '')
    setup.py: platform.libc_ver() => ('', '')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = []
    setup.py: library_dirs = ['/usr/local/lib']
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-macbkK/pymssql/setup.py", line 477, in <module>
        ext_modules = ext_modules(),
      File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 268, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 313, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 846, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1091, in best_match
        return self.obtain(req, installer)
      File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1103, in obtain
        return installer(requirement)
      File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 380, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 633, in easy_install
        raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('setuptools-git')

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-macbkK/pymssql/

(与 相同的错误pyodbc)当我尝试安装时setuptools-git(如错误消息所述),出现gcc编译错误。

除了尝试之外pip install...,我还使用直接从 Alpine Linux 存储库下载了 SQLAlchemy 库apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ py-sqlalchemy,但安装仍然失败/python 库仍然失败。

我在 Alpine Linux 和 Microsoft SQL Server 上找到的文档很少,所以我想知道我是否遗漏了一些说它们不兼容的东西。有没有人尝试过这样做?如果不建议通过 Python 连接,我正在考虑通过 Shell 命令进行连接,任何人都可以为此建议最佳实践吗?

谢谢!

4

3 回答 3

2

您必须先安装 odbc 驱动程序。因此,将其添加到您的 docker 文件中,然后安装 pyodbc

apk add g++ gcc unixodbc-dev

于 2017-08-10T10:39:50.323 回答
1

微软已正式开始支持在 Alpine 上安装 ODBC 驱动程序。

于 2020-04-23T05:51:48.573 回答
0

我这里的相关问题

我记得安装msodbcsql17驱动程序以连接到 sql server。但是我使用 Ubuntu 18.04 作为我的 docker 的基础镜像,并且 sql server 是在 azure 上。另外我必须安装unixodbc unixodbc-dev gcc g++ gfortran,所以不确定这是否对你有帮助。

但是当我尝试将 alpine 作为基本图像时,这是不可能的。

在 github 上发现了一个相关问题,但它在 msphpsql repo 下,所以我不确定它是否适用于 alpine 的一般驱动程序。它说MS还不支持。

官方 MS 安装页面有仅适用于 Debian、RedHat、SUSE、Ubuntu 的安装说明。

于 2019-08-30T09:36:15.687 回答