在heroku上部署matplotlib失败。如何正确操作?

2024-10-01 09:16:30 发布

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

我用pip在我的virtualenv中安装了matplotlib。一开始是个失败,但是在我完成easy_install -U distribute之后,安装就顺利进行了。在

以下是我要做的(在git存储库根文件夹中):

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

然后,我做一个要求.txt通过使用pip freeze > requirements.txt。结果如下:

^{pr2}$

尝试部署应用程序时出现问题:

(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它可能没有被pip记录。在

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

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


Tags: installpiptopygitenvtxtapp
3条回答

我在使用matplotlib和{}时也有困难,答案很难找到。This帮了我。在

基本上你要做的就是push the project with numpyrequirements.txt中。只有在这之后,我们必须add pandas and matplotlib到{}。在

我终于可以应付了。在

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

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

然后我换了要求.txt在这方面:

^{pr2}$

这里最重要的部分是安装matplotlib1.1.0(目前最新的是1.3.0)。可能会出现一些“不推荐使用的numpy API”警告。但在我的情况下似乎没什么大不了的。在

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

A matplotlib generated figure

对于那些目前正在查找这个答案的人,我只是在最新的heroku上部署了最新的matplotlib/numpy作为一个需求(分别是1.4.3和1.9.2),没有任何问题。在

相关问题 更多 >