Error deploying on Heroku (ReportLab)

有些话、适合烂在心里 提交于 2020-01-25 14:20:50

问题


I want to deploy a python / django application on Heroku. In the local environment everything works fine. I use pip to install packages. My requirements.txt is the following:

Django==1.6.2
Pillow==2.4.0
dj-database-url==0.3.0
dj-static==0.0.5
django-ckeditor-updated==4.2.8
django-toolbelt==0.0.1
gunicorn==18.0
html5lib==1.0b3
mongoengine==0.8.7
psycopg2==2.5.2
pyPdf==1.13
pymongo==2.7
pystache==0.5.3
reportlab==3.1.8
six==1.6.1
static==1.0.2
wsgiref==0.1.2
xhtml2pdf==0.0.5

But when deploying on Heroku with the command "git push heroku master" I get the error on "ReportLab" installation:

           gcc -pthread -shared build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/_renderPM.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/gt1/gt1-parset1.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/gt1/gt1-dict.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/gt1/gt1-namecontext.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/gt1/gt1-region.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_vpath_bpath.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb_pixbuf_affine.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb_svp.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp_vpath.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp_vpath_stroke.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp_ops.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_vpath.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_vpath_dash.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_affine.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rect.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb_affine.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb_affine_private.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_rgb_rgba_affine.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp_intersect.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_svp_render_aa.o build/temp.linux-x86_64-2.7/tmp/pip_build_u4591/reportlab/src/rl_addons/renderPM/libart_lgpl/art_misc.o -L/usr/local/lib -L/usr/lib -L/app/.heroku/python/lib -L/app/.heroku/python/lib -lfreetype -lpython2.7 -o build/lib.linux-x86_64-2.7/reportlab/graphics/_renderPM.so

           /usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC

           /usr/local/lib/libpython2.7.a: could not read symbols: Bad value

           collect2: ld returned 1 exit status

           error: command 'gcc' failed with exit status 1

           ----------------------------------------
           Cleaning up...
           Command /app/.heroku/python/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_u4591/reportlab/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-F4RTRK-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_u4591/reportlab
    Traceback (most recent call last):
      File "/app/.heroku/python/bin/pip", line 9, in <module>
        load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
      File "/app/.heroku/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/__init__.py", line 185, in main
        return command.main(cmd_args)
      File "/app/.heroku/python/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 161, in main
        text = '\n'.join(complete_log)
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 38: ordinal not in range(128)

     !     Push rejected, failed to compile Python app

    To git@heroku.com:mysterious-oasis-7382.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'git@heroku.com:mysterious-oasis-7382.git'

Jeromes-MacBook-Pro:diagnosystem_proj Jerome$ 

Your help is appreciated to resolve this issue.


回答1:


The problem seems to be caused by the presence of a static Python 2.7 library in /usr/local/lib/libpython2.7.a ; to install Reportlab on Heroku correctly using the python-2.7.7 runtime, I changed the order of the directories enumerated by the __call__ function in the inc_lib_dirs class of Reportlab's setup.py file as follows:

Original:

class inc_lib_dirs:
    L = None
    I = None
    def __call__(self):
        if self.L is None:
            L = []
            I = []
            if platform == "cygwin":
                aDir(L, os.path.join("/usr/lib", "python%s" % sys.version[:3], "config"))
            elif platform == "darwin":
                # attempt to make sure we pick freetype2 over other versions
                aDir(I, "/sw/include/freetype2")
                aDir(I, "/sw/lib/freetype2/include")
                # fink installation directories
                aDir(L, "/sw/lib")
                aDir(I, "/sw/include")
                # darwin ports installation directories
                aDir(L, "/opt/local/lib")
                aDir(I, "/opt/local/include")
            aDir(I, "/usr/local/include")
            aDir(L, "/usr/local/lib")
            aDir(I, "/usr/include")
            aDir(L, "/usr/lib")
            aDir(I, "/usr/include/freetype2")
            prefix = sysconfig.get_config_var("prefix")
            if prefix:
                aDir(L, pjoin(prefix, "lib"))
                aDir(I, pjoin(prefix, "include"))
            self.L=L
            self.I=I
        return self.I,self.L
inc_lib_dirs=inc_lib_dirs()

Edited:

class inc_lib_dirs:
    L = None
    I = None
    def __call__(self):
        if self.L is None:
            L = []
            I = []
            if platform == "cygwin":
                aDir(L, os.path.join("/usr/lib", "python%s" % sys.version[:3], "config"))
            elif platform == "darwin":
                # attempt to make sure we pick freetype2 over other versions
                aDir(I, "/sw/include/freetype2")
                aDir(I, "/sw/lib/freetype2/include")
                # fink installation directories
                aDir(L, "/sw/lib")
                aDir(I, "/sw/include")
                # darwin ports installation directories
                aDir(L, "/opt/local/lib")
                aDir(I, "/opt/local/include")
            prefix = sysconfig.get_config_var("prefix")
            if prefix:
                aDir(L, pjoin(prefix, "lib"))
                aDir(I, pjoin(prefix, "include"))
            aDir(I, "/usr/local/include")
            aDir(L, "/usr/local/lib")
            aDir(I, "/usr/include")
            aDir(L, "/usr/lib")
            aDir(I, "/usr/include/freetype2")
            self.L=L
            self.I=I
        return self.I,self.L
inc_lib_dirs=inc_lib_dirs()

I'd love to find a cleaner solution to avoid keeping a modified version in my egg repository.



来源:https://stackoverflow.com/questions/24143783/error-deploying-on-heroku-reportlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!