【问题标题】:Failed to Deploy to Heroku Platform部署到 Heroku 平台失败
【发布时间】:2020-07-02 11:37:51
【问题描述】:

我正在创建一个 html Web 表单,我希望从中将数据存储到本地计算机中。运行该程序时,它在我的本地机器上运行良好。

当我将程序推送到 Heroku 平台时,它失败了。

   ----main file
   -------Procfile
   -------requirements.txt
   -------runtime.txt
   -------main.py
   -------static
   ----templates
   ------index.html
   ----static
   ------index_css.css

过程文件:

     web: gunicorn main:app

要求:

    flask==1.1.1
    flask-mysqldb==0.2.0
    gunicorn==19.9.0
    pyodbc==4.0.30

运行时:

    python-3.7.2

在 Heroku 平台上部署时出错:

    Building wheel for pyodbc (setup.py): started
     Building wheel for pyodbc (setup.py): finished with status 'error'
     ERROR: Command errored out with exit status 1:
      command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q2igx1jr/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q2igx1jr/pyodbc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-8r1wqs6z
          cwd: /tmp/pip-install-q2igx1jr/pyodbc/
     Complete output (16 lines):
     /app/.heroku/python/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
       warnings.warn(msg)
     running bdist_wheel
     running build
     running build_ext
     building 'pyodbc' extension
     creating build
     creating build/temp.linux-x86_64-3.7
     creating build/temp.linux-x86_64-3.7/src
     gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/app/.heroku/python/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
     In file included from src/buffer.cpp:12:0:
     src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
      #include <sql.h>
               ^~~~~~~
     compilation terminated.
     error: command 'gcc' failed with exit status 1
     ----------------------------------------
     ERROR: Failed building wheel for pyodbc
     Running setup.py clean for pyodbc
     Building wheel for mysqlclient (setup.py): started
     Building wheel for mysqlclient (setup.py): finished with status 'done'
     Created wheel for mysqlclient: filename=mysqlclient-2.0.0-cp37-cp37m-linux_x86_64.whl size=100868 sha256=ffd0776f2d39a5405cc1ac1465a08f48ee9da558c172105866f17378a6edebbd
     Stored in directory: /tmp/pip-ephem-wheel-cache-5xsag9fy/wheels/80/87/ff/4ea9d03e0a265ef3a4a0cdf0cf1e4786c37665c4015b2ece83
   Successfully built flask-mysqldb mysqlclient
   Failed to build pyodbc
   Installing collected packages: Werkzeug, click, itsdangerous, MarkupSafe, Jinja2, flask, mysqlclient, flask-mysqldb, gunicorn, pyodbc
       Running setup.py install for pyodbc: started
       Running setup.py install for pyodbc: finished with status 'error'
       ERROR: Command errored out with exit status 1:
        command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q2igx1jr/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q2igx1jr/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-record-oz00635z/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.7m/pyodbc
            cwd: /tmp/pip-install-q2igx1jr/pyodbc/
       Complete output (16 lines):
       /app/.heroku/python/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
         warnings.warn(msg)
       running install
       running build
       running build_ext
       building 'pyodbc' extension
       creating build
       creating build/temp.linux-x86_64-3.7
       creating build/temp.linux-x86_64-3.7/src
       gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/app/.heroku/python/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
       In file included from src/buffer.cpp:12:0:
       src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
        #include <sql.h>
                 ^~~~~~~
       compilation terminated.
       error: command 'gcc' failed with exit status 1
       ----------------------------------------
   ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-q2igx1jr/pyodbc/setup.py'"'"'; __file__='"'"'/tmp/pip-install-q2igx1jr/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-record-oz00635z/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.7m/pyodbc Check the logs for full command output.
Push rejected, failed to compile Python app.
Push failed

我是 Heroku 的新手,不知道如何解决这个错误。

【问题讨论】:

  • 您必须创建一个env 文件夹,该文件夹必须包含项目中使用的所有依赖项,例如flask numpy 等观看此视频以获得一个想法:youtube.com/watch?v=n1P8B53CCxs
  • 我创建了一个包含所有依赖项的 requirements.txt 文件,那为什么还要创建一个 env 呢?
  • 我关注了视频,但仍然遇到同样的错误

标签: python heroku pyodbc


【解决方案1】:

在 Procfile 中,您可以更改: 网站:gunicorn main.wsgi

【讨论】:

    猜你喜欢
    • 2014-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 2021-05-27
    相关资源
    最近更新 更多