微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在heroku上部署matplotlib失败如何正确做到这一点?

如何解决在heroku上部署matplotlib失败如何正确做到这一点?

终于,我能够解决这个问题。

首先,我使用此buildpack:https : //github.com/dbrgn/heroku-buildpack-python- sklearn 要使用此buildpack,请运行以下命令(也许这不是必要步骤):

heroku config:set BUILDPACK_URL=https://github.com/dbrgn/heroku-buildpack-python-sklearn/

然后我将requirements.txt更改为:

argparse==1.2.1
distribute==0.6.24
gunicorn==17.5
wsgiref==0.1.2
numpy==1.7.0
matplotlib==1.1.0
scipy==0.11.0
scikit-learn==0.13.1

这里最重要的部分是我安装了matplotlib 1.1.0(当前最新的是1.3.0)。可能会出现一些“不推荐使用的numpy API”警告。但就我而言,这似乎还不错。

结果如下(由于我使用的是免费服务器,因此页面站点可能已关闭http://kokoropy.herokuapp.com/example/plotting

matplotlib生成的图

解决方法

我已经使用pip在我的virtualenv中安装了matplotlib。刚开始时是失败的,但是我这样做之后easy_install -Udistribute,安装顺利进行。

这是我的工作(在我的git仓库根文件夹中):

virtualenv env
source env/bin/activate
pip install gunicorn
pip install numpy
easy_install -U distribute
pip install matplotlib

然后,我通过使用制作了requirements.txt pip freeze > requirements.txt。结果如下:

argparse==1.2.1
distribute==0.7.3
gunicorn==17.5
matplotlib==1.3.0
nose==1.3.0
numpy==1.7.1
pyparsing==2.0.1
python-dateutil==2.1
six==1.3.0
tornado==3.1
wsgiref==0.1.2

当我尝试部署应用程序时发生了问题:

(env)gofrendi@kirinThor:~/kokoropy$ git push -u heroku
Counting objects: 9,done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5),done.
Writing objects: 100% (5/5),586 bytes,done.
Total 5 (delta 3),reused 0 (delta 0)

-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Using Python runtime (python-2.7.4)
-----> Installing dependencies using Pip (1.3.1)
       Downloading/unpacking distribute==0.7.3 (from -r requirements.txt (line 2))
         Running setup.py egg_info for package distribute

       Downloading/unpacking matplotlib==1.3.0 (from -r requirements.txt (line 4))
         Running setup.py egg_info for package matplotlib
           The required version of distribute (>=0.6.28) is not available,and can't be installed while this script is running. Please
           install a more recent version first,using
           'easy_install -U distribute'.

           (Currently using distribute 0.6.24 (/app/.heroku/python/lib/python2.7/site-packages))
           Complete output from command python setup.py egg_info:
           The required version of distribute (>=0.6.28) is not available,and can't be installed while this script is running. Please

       install a more recent version first,using

       'easy_install -U distribute'.



       (Currently using distribute 0.6.24 (/app/.heroku/python/lib/python2.7/site-packages))

       ----------------------------------------
       Command python setup.py egg_info failed with error code 2 in /tmp/pip-build-u55833/matplotlib
       Storing complete log in /app/.pip/pip.log

 !     Push rejected,failed to compile Python app

To git@heroku.com:kokoropy.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:kokoropy.git'
(env)gofrendi@kirinThor:~/kokoropy$

似乎heroku服务器无法正确安装matplotlib。

当我这样做时easy_install -U distribute,可能不会被点子记录。

Matplotlib也具有几个非python库依赖(例如:libjpeg8-dev,libfreetype和libpng6-dev)。我可以在本地安装这些依赖项(例如:通过apt- get)。但是,这也不会被pip记录。

所以,我的问题是:如何在heroku部署服务器中正确安装matplotlib?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。