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

2024-05-14 00:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我在将我的项目部署到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')

Tags: pybuildconfigappshareincludelinuxusr
1条回答
网友
1楼 · 发布于 2024-05-14 00:12:52

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

相关问题 更多 >