GCP无法使用install pyodbc进行部署 [英] GCP Cann't deploy with install pyodbc

查看:97
本文介绍了GCP无法使用install pyodbc进行部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将GCP (谷歌云平台): API服务与python项目一起使用.这个项目需要使用lib:pyodbc来连接到MSSQL. 在 localhost 中很好,但是当我尝试将此项目部署到GCP时,它显示出这样的错误.有人可以帮我解决这个问题吗?

I'm try to use GCP (Google cloud platform) : API Service with python project. And this project need to use lib : pyodbc for connect to MSSQL. In localhost it fine but when I try to deploy this project to GCP it show error like this. Can someone help me with this issue?

推荐答案

将运行该应用程序的计算机必须已安装 ODBC头文件.

The machine that will run the app must have ODBC header files installed.

为此,您将需要在自定义运行时环境中部署应用程序,在此环境中安装此头文件,然后再安装需求.有关如何执行此操作的更多信息,您可以访问有关此堆栈溢出问题的答案.

To do so, you will need to deploy the app in a custom run time environment, where you install this header files before installing the requirements. For more information on how to do so you can visit this answer on this Stack-overflow question.

我还将在上面提到的堆栈溢出问题中发布 Brooks Lybrand 所述的过程:他的解决方案基于将docker python通过pyodbc )

I will also post here the process as described by Brooks Lybrand in Stack-overflow question mentioned above: (His solution is based on Connect docker python to SQL server with pyodbc)

  1. 在与您的应用相同的目录中执行$ gcloud beta app gen-config --custom.
  2. 将创建一个Dockerfile.
  3. 通过在RUN pip install -r requirements.txt之前添加以下命令来编辑Dockerfile(建议:在RUN virtualenv ...之后和# Set virtualenv environment variables ...之前添加这些行):

  1. Execute $ gcloud beta app gen-config --custom in the same directory with your app.
  2. A Dockerfile will be created.
  3. Edit the Dockerfile by adding the following commands before the RUN pip install -r requirements.txt (suggestion: add those lines after RUN virtualenv ... and before # Set virtualenv environment variables ...):

#Install FreeTDS and dependencies for PyODBC RUN apt-get update RUN apt-get install -y tdsodbc unixodbc-dev RUN apt install unixodbc-bin -y RUN apt-get clean -y ADD odbcinst.ini /etc/odbcinst.ini

#Install FreeTDS and dependencies for PyODBC RUN apt-get update RUN apt-get install -y tdsodbc unixodbc-dev RUN apt install unixodbc-bin -y RUN apt-get clean -y ADD odbcinst.ini /etc/odbcinst.ini

创建文件odbcinst.ini(如果尚不存在)

Create a file odbcinst.ini if doesn't exist already

编辑文件odbcinst.ini并添加以下内容:

Edit the file odbcinst.ini and add the following:

[FreeTDS] Description=FreeTDS Driver Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

[FreeTDS] Description=FreeTDS Driver Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

执行$ gcloud app deploy,它应该可以毫无问题地部署.

Execute $ gcloud app deploy and it should deploy without any problems.

我自己进行了测试,但遇到了同样的错误.完成此过程后,该应用程序已部署,没有任何问题.

I have tested it myself and I was getting the same error. After this procedure the App was deployed without any issues.

这篇关于GCP无法使用install pyodbc进行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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