我正在尝试将我的应用程序部署到 Heroku。它使用 pyOpenSSL
,它需要 cryptography
,它需要 libffi
。我在这里找到了一个包含 libffi
的自定义 buildpack: https://github.com/mfenniak/heroku-buildpack-python-libffi 。但是, cryptography
似乎无法找到 libffi
即使它在 LD_LIBRARY_PATH
上:
$ heroku run bash
heroku> echo $LD_LIBRARY_PATH
/app/.heroku/vendor/lib:/app/vendor/libffi-3.0/lib
heroku> ls /app/vendor/libffi-3.0/lib
libffi-3.0.13 libffi.a libffi.la libffi.so libffi.so.6 libffi.so.6.0.1 pkgconfig
但是,我不确定
LD_LIBRARY_PATH
在安装过程中是否可用,但它是 buildpack 编译步骤的一部分:https://github.com/mfenniak/heroku-buildpack-python-libffi/commit/6ce48d4fd6c55fc3dc462cf6300c17854732b6e2一般来说,这个 buildpack 可以工作,我之前将它与
bcrypt
( https://pypi.python.org/pypi/bcrypt ) 一起使用。这是失败的heroku部署过程:
$ git push staging master
Fetching repository, done.
Counting objects: 20, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.71 KiB | 0 bytes/s, done.
Total 11 (delta 9), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Using Python runtime (python-2.7.4)
-----> Noticed cffi. Bootstrapping libffi.
PKG_CONFIG_PATH=:/app/vendor/libffi-3.0/lib/pkgconfig/
libffi.pc is in-place at /app/vendor/libffi-3.0/vendor/lib/pkgconfig/libffi.pc, libffi-based builds should work!
-----> Installing dependencies using Pip (1.3.1)
Obtaining file:///app (from -r requirements.txt (line 1))
Running setup.py egg_info for package from file:///app
Downloading/unpacking pyOpenSSL==0.14 (from -r requirements.txt (line 76))
Running setup.py egg_info for package pyOpenSSL
no previously-included directories found matching 'doc/_build'
Downloading/unpacking cryptography==0.2.2 (from -r requirements.txt (line 77))
Running setup.py egg_info for package cryptography
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-u45370/cryptography/setup.py", line 113, in <module>
"build": cffi_build,
File "/app/.heroku/python/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/app/.heroku/python/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/app/.heroku/python/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "<string>", line 14, in replacement_run
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 259, in find_sources
mm.run()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 325, in run
self.add_defaults()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 361, in add_defaults
sdist.add_defaults(self)
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/sdist.py", line 199, in add_defaults
build_py = self.get_finalized_command('build_py')
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
cmd_obj.ensure_finalized()
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/build_py.py", line 73, in finalize_options
_build_py.finalize_options(self)
File "/app/.heroku/python/lib/python2.7/distutils/command/build_py.py", line 46, in finalize_options
('force', 'force'))
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 298, in set_undefined_options
src_cmd_obj.ensure_finalized()
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/tmp/pip-build-u45370/cryptography/setup.py", line 52, in finalize_options
from cryptography.hazmat.primitives import constant_time, padding
File "cryptography/hazmat/primitives/constant_time.py", line 21, in <module>
_ffi = cffi.FFI()
File "/app/.heroku/python/lib/python2.7/site-packages/cffi/api.py", line 56, in __init__
import _cffi_backend as backend
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/cryptography.egg-info
writing requirements to pip-egg-info/cryptography.egg-info/requires.txt
writing pip-egg-info/cryptography.egg-info/PKG-INFO
writing top-level names to pip-egg-info/cryptography.egg-info/top_level.txt
writing dependency_links to pip-egg-info/cryptography.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/cryptography.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/tmp/pip-build-u45370/cryptography/setup.py", line 113, in <module>
"build": cffi_build,
File "/app/.heroku/python/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/app/.heroku/python/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/app/.heroku/python/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "<string>", line 14, in replacement_run
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 259, in find_sources
mm.run()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 325, in run
self.add_defaults()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 361, in add_defaults
sdist.add_defaults(self)
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/sdist.py", line 199, in add_defaults
build_py = self.get_finalized_command('build_py')
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
cmd_obj.ensure_finalized()
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/app/.heroku/python/lib/python2.7/site-packages/setuptools/command/build_py.py", line 73, in finalize_options
_build_py.finalize_options(self)
File "/app/.heroku/python/lib/python2.7/distutils/command/build_py.py", line 46, in finalize_options
('force', 'force'))
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 298, in set_undefined_options
src_cmd_obj.ensure_finalized()
File "/app/.heroku/python/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
self.finalize_options()
File "/tmp/pip-build-u45370/cryptography/setup.py", line 52, in finalize_options
from cryptography.hazmat.primitives import constant_time, padding
File "cryptography/hazmat/primitives/constant_time.py", line 21, in <module>
_ffi = cffi.FFI()
File "/app/.heroku/python/lib/python2.7/site-packages/cffi/api.py", line 56, in __init__
import _cffi_backend as backend
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-u45370/cryptography
Storing complete log in /app/.pip/pip.log
! Push rejected, failed to compile Python app
To [email protected]:my-app-staging.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:my-app-staging.git'
更新
奇怪的是,如果我 ssh 到一个 dyno
heroku run bash
然后 pip install pyOpenSSL
,那么它就成功了。但这似乎无助于弄清楚部署过程出了什么问题。 最佳答案
似乎 github 用户 kennethjiang 遇到了同样的问题,并在四天前通过修复对 custom libffi buildpack 进行了 fork 。
以下是相关的变化:
https://github.com/kennethjiang/heroku-buildpack-python-libffi/compare/3bb5fab8213f41411f515f21a6c83ff36c8aa1f2...8ef02
$ heroku config:add BUILDPACK_URL=git://github.com/kennethjiang/heroku-buildpack-python-libffi.git
$ git push heroku master
Initializing repository, done.
Counting objects: 3, done.
Writing objects: 100% (3/3), 260 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Preparing Python runtime (python-2.7.4)
-----> Installing Distribute (0.6.36)
-----> Installing Pip (1.3.1)
-----> Noticed cffi. Bootstrapping libffi.
PKG_CONFIG_PATH=:/app/vendor/libffi-3.0/lib/pkgconfig/
libffi.pc is in-place at /app/vendor/libffi-3.0/vendor/lib/pkgconfig/libffi.pc, libffi-based builds should work!
-----> Installing dependencies using Pip (1.3.1)
Downloading/unpacking pyOpenSSL==0.14 (from -r requirements.txt (line 1))
Running setup.py egg_info for package pyOpenSSL
no previously-included directories found matching 'doc/_build'
Downloading/unpacking cryptography==0.2.2 (from -r requirements.txt (line 2))
Running setup.py egg_info for package cryptography
no previously-included directories found matching 'documentation/_build'
zip_safe flag not set; analyzing archive contents...
six: module references __file__
six: module references __path__
Installed /tmp/pip-build-u24412/cryptography/six-1.6.1-py2.7.egg
Searching for cffi>=0.8
Reading http://pypi.python.org/simple/cffi/
Best match: cffi 0.8.2
Downloading https://pypi.python.org/packages/source/c/cffi/cffi-0.8.2.tar.gz#md5=37fc88c62f40d04e8a18192433f951ec
Processing cffi-0.8.2.tar.gz
Writing /tmp/easy_install-vYzEMy/cffi-0.8.2/setup.cfg
Running cffi-0.8.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vYzEMy/cffi-0.8.2/egg-dist-tmp-KU0RrQ
cc -c c/check__thread.c -o c/check__thread.o
Installed /tmp/pip-build-u24412/cryptography/cffi-0.8.2-py2.7-linux-x86_64.egg
...
Successfully installed pyOpenSSL cryptography six cffi pycparser
Cleaning up...
-----> Discovering process types
Procfile declares types -> (none)
-----> Compressing... done, 27.9MB
-----> Launching... done, v5
http://quiet-atoll-6802.herokuapp.com/ deployed to Heroku
To [email protected]:quiet-atoll-6802.git
* [new branch] master -> master
关于python - 自定义 LIBFFI Heroku buildpack 的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22415725/