将具有C依赖性的Python库部署到Heroku

问题描述 投票:0回答:1

我在将项目部署到Heroku时感到有些沮丧。它取决于占星术软件的一些python库,这些库在我的本地计算机上运行良好。但是这些库之一要求您下载一些文件并设置下载文件的路径才能运行,我认为它在构建过程中此刻失败。该库是对最初用C语言编写的另一个库的Python扩展。python库为here。我一直在看hereherehere的一些文档,但是我从未构建过docker映像,我甚至不确定它是否可以解决我的问题。我还考虑过添加一个新的buildpack,但也不确定它是否可以解决问题。我的错误在下面,希望有人可以指出正确的方向。我主要是在寻找可以告诉我是否可以使用Docker解决我的问题的人,这样我就不会在没有帮助的情况下浪费时间。谢谢。

Installing collected packages: pyswisseph
2020-05-20T00:01:48.839661+00:00 app[web.1]: Running setup.py install for pyswisseph: started
2020-05-20T00:01:48.839662+00:00 app[web.1]: Running setup.py install for pyswisseph: finished with status 'error'
2020-05-20T00:01:48.839662+00:00 app[web.1]:
2020-05-20T00:01:48.839801+00:00 app[web.1]: ERROR: Command errored out with exit status 1:
2020-05-20T00:01:48.839814+00:00 app[web.1]: command: /app/.local/share/virtualenvs/app-4PlAip0Q
/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-djfmycyt
/pyswisseph/setup.py'"'"'; __file__='"'"'/tmp/pip-install-djfmycyt/pyswisseph/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-vuz1lu7j
2020-05-20T00:01:48.839815+00:00 app[web.1]: cwd: /tmp/pip-install-djfmycyt/pyswisseph/
2020-05-20T00:01:48.839815+00:00 app[web.1]: Complete output (23 lines):
2020-05-20T00:01:48.839816+00:00 app[web.1]: Searching system libswe...
2020-05-20T00:01:48.839816+00:00 app[web.1]: pkg-config not found
2020-05-20T00:01:48.839816+00:00 app[web.1]: Using internal libswe
2020-05-20T00:01:48.839817+00:00 app[web.1]: /app/.local/share/virtualenvs/app-4PlAip0Q
/lib/python3.7/site-packages/setuptools/dist.py:454: UserWarning: Normalizing '2.08.00-1' to 
'2.8.0.post1'

2020-05-20T00:01:48.839817+00:00 app[web.1]: warnings.warn(tmpl.format(**locals()))
2020-05-20T00:01:48.839818+00:00 app[web.1]: running bdist_wheel
2020-05-20T00:01:48.839818+00:00 app[web.1]: running build
2020-05-20T00:01:48.839818+00:00 app[web.1]: running build_ext
2020-05-20T00:01:48.839818+00:00 app[web.1]: building 'swisseph' extension
2020-05-20T00:01:48.839819+00:00 app[web.1]: creating build
2020-05-20T00:01:48.839819+00:00 app[web.1]: creating build/temp.linux-x86_64-3.7
2020-05-20T00:01:48.839819+00:00 app[web.1]: creating build/temp.linux-x86_64-3.7/libswe
2020-05-20T00:01:48.839820+00:00 app[web.1]: creating build/temp.linux-x86_64-3.7/swephelp
2020-05-20T00:01:48.839823+00:00 app[web.1]: gcc -pthread -Wno-unused-result -Wsign-compare
 -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Ilibswe -Iswephelp -I/app/.local/share/virtualenvs
/app-4PlAip0Q/include -I/app/.heroku/python/include/python3.7m -c pyswisseph.c -o 
build/temp.linux-x86_64-3.7/pyswisseph.o -std=gnu99
2020-05-20T00:01:48.839824+00:00 app[web.1]: In file included from /usr/lib/gcc/x86_64-linux-
gnu/7/include-fixed/syslimits.h:7:0,
2020-05-20T00:01:48.839824+00:00 app[web.1]: from /usr/lib/gcc/x86_64-linux-gnu/7/include-

fixed/limits.h:34,
2020-05-20T00:01:48.839825+00:00 app[web.1]: from /app/.heroku/python/include/python3.7m/Python.h:11,
2020-05-20T00:01:48.839825+00:00 app[web.1]: from pyswisseph.c:58:
2020-05-20T00:01:48.839828+00:00 app[web.1]: /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:194:15: fatal error: limits.h: No such file or directory
2020-05-20T00:01:48.839829+00:00 app[web.1]: #include_next <limits.h>  /* recurse down to the
 real one */
2020-05-20T00:01:48.839829+00:00 app[web.1]: ^~~~~~~~~~
2020-05-20T00:01:48.839829+00:00 app[web.1]: compilation terminated.
2020-05-20T00:01:48.839846+00:00 app[web.1]: error: command 'gcc' failed with exit status 1
2020-05-20T00:01:48.839847+00:00 app[web.1]: ----------------------------------------
2020-05-20T00:01:48.839847+00:00 app[web.1]: ERROR: Failed building wheel for pyswisseph

编辑-这是示例setup.py代码,仅供参考:

# Test for pkg-config
has_pkgconfig = False
if swe_detection:
    print('Searching system libswe...')
    try:
        import subprocess
        try:
            subprocess.check_output(['pkg-config'], stderr=subprocess.STDOUT)
        except AttributeError: # < Python 2.7
            # detection without pkg-config (or use popen)
            pass
    except subprocess.CalledProcessError:
        has_pkgconfig = True
        print('Found pkg-config')
    except OSError:
        print('pkg-config not found')
        pass
    except ImportError: # Python < 2.4
        pass
    #

# Find libswe-dev
libswe_found = False
if has_pkgconfig:
    try:
        swe_includes = subprocess.check_output(
            ['pkg-config', '--cflags', 'libswe-'+swe_version],
            stderr=subprocess.STDOUT)
        swe_libs = subprocess.check_output(
            ['pkg-config', '--libs', 'libswe-'+swe_version],
            stderr=subprocess.STDOUT)
        swe_sources = []
        swe_depends = []
        swe_defines = [('PYSWE_DEFAULT_EPHE_PATH',
            '"/usr/share/libswe/ephe2:/usr/share/libswe/ephe"')]
        libswe_found = True
        print('pkg-config found libswe-'+swe_version)
    except subprocess.CalledProcessError:
        pass
    #

# Another attempt at finding libswe-dev -- without pkg-config
# (pkg-config may be uninstalled but pc file should be in place)
# (and assuming there is only one version installed...)
if ( swe_detection and not libswe_found
    and os.path.isfile( '/usr/lib/pkgconfig/libswe-'+swe_version+'.pc' )):
    swe_includes = ['/usr/include']
    swe_sources = []
    swe_depends = []
    swe_libs = ['swe']
    swe_defines = [('PYSWE_DEFAULT_EPHE_PATH',
        '"/usr/share/libswe/ephe2:/usr/share/libswe/ephe"')]
    print('Found system libswe')
python c linux docker heroku
1个回答
0
投票

我已解决问题。我认为构建过程变得很复杂,因为我有一个试图运行Python脚本的Rails应用程序,并且我有两个可能冲突的不同buildpack。我仅使用Python / Flask(到目前为止,只有一页用于测试部署)重写了我的应用程序,并且这似乎可行(至少我没有导入/构建错误)。因此,对于任何在看这个问题的人来说,这就是我的解决办法。我使用pipenv / Pipfile而不是venv或virtualenv和gunicorn进行部署。

© www.soinside.com 2019 - 2024. All rights reserved.