在heroku上部署matplotlib失败了.怎么做到这一点?

goF*_*ard 4 python matplotlib heroku python-2.7

我使用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
Run Code Online (Sandbox Code Playgroud)

然后,我使用了make.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
Run Code Online (Sandbox Code Playgroud)

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

(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$ 
Run Code Online (Sandbox Code Playgroud)

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

当我这样做时easy_install -U distribute,可能不会被pip记录.

Matplotlib还有几个非python-library依赖项(例如:libjpeg8-dev,libfreetype和libpng6-dev).我可以在本地安装这些依赖项(例如:via apt-get).但是,这也不是由pip记录的.

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

goF*_*ard 6

最后我能够管理这个.

首先,我使用这个buildpack:https://github.com/dbrgn/heroku-buildpack-python-sklearn 要使用这个buildpack我运行它(也许这不是必要的步骤):

heroku config:set BUILDPACK_URL=https://github.com/dbrgn/heroku-buildpack-python-sklearn/
Run Code Online (Sandbox Code Playgroud)

然后我将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
Run Code Online (Sandbox Code Playgroud)

这里最重要的部分是我安装matplotlib 1.1.0(目前最新的是1.3.0).可能会发生一些"弃用的numpy API"警告.但就我而言,它似乎没问题.

这是结果(页面网站可能因为我使用免费服务器而下降) http://kokoropy.herokuapp.com/example/plotting

matplotlib生成的图