2

How can I install numpy,scipy,matplotlib on Heroku?

So first locally I'm doing pip install matplotlib -> i get an error saying install numpy.. so i do pip install numpy and get an error saying

  File "/home/sghose/myapp/helloflask/build/numpy/numpy/distutils/command/build_src.py", line 385, in generate_sources

    source = func(extension, build_dir)

  File "numpy/core/setup.py", line 410, in generate_config_h

    moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)

  File "numpy/core/setup.py", line 41, in check_types

    out = check_types(*a, **kw)

  File "numpy/core/setup.py", line 271, in check_types

    "Cannot compile 'Python.h'. Perhaps you need to "\

SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/sghose/myapp/helloflask/build/numpy

...what do I do now? Typically I would just do apt-get install python-numpy ... but then I'm thinking pip won't pick it up and then Heroku will be unhappy when I push... also I see a previous post where they recompiled numpy,scipy, matplotlib and changed vars so that they pointed to heroku packages (http://stackoverflow.com/questions/9819968/running-scipy-on-heroku) ? Is this still necessary? Sounds somewhat painful >_<

Eiyrioü von Kauyf
  • 4,481
  • 7
  • 32
  • 41

2 Answers2

3

How Heroku installs dependencies

When you push code to Heroku, Heroku will only look at your requirements.txt file and install the packages that are listed in there.

How you list those dependencies

Heroku doesn't care about how you created that file (by hand, or using pip freeze), so nothing prevents you from adding a package to the requirements.txt file, you just have to add a line in there with the name of the requirement.

How that solves your issue

Once you add the matplotlib line to your requirements.txt file, you can then push your code to Heroku, and they will figure out what to do with your matplotlib requirement.

If that doesn't work, you can always contact Heroku, but if the only requirement is the python headers, I'd be surprised if it wasn't available on Heroku.


Regarding local installation, Ben Mezger's answer is right, you just have to:

  • apt-get install the python headers (these are not a python package, so you don't install them with pip). Heroku likely has those available already.
  • Install the package using pip, it will then compile properly.
Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
  • um... I don't understand sorry. How do I know the matplotlib version number? .. but that is more trivial. my real problem is how will it get heroku to download matplotlib.. i doubt it will apt-get it? – Eiyrioü von Kauyf Oct 30 '12 at 00:50
  • *is this assuming that they have the python headers so pip will work? – Eiyrioü von Kauyf Oct 30 '12 at 00:50
  • @EiyrioüvonKauyf Yes. I think they do have those headers. They will use `pip` to install what's in your `requirements.txt` file. The whole point of using Heroku is not having to care. Just drop the requirement in your file and you're set. By the way, the version number is optional in a `requirements.txt` file – Thomas Orozco Oct 30 '12 at 00:52
  • @EiyrioüvonKauyf I updated my answer to make it a bit clearer, let me know if it's still unclear. – Thomas Orozco Oct 30 '12 at 00:55
0

You need to install python-dev

apt-get install python-dev

or

apt-get install python-devel
  • .... but via pip? pastie.org/5135107 -> cannot find. From my understanding if i used apt-get pip won't pick it up, and then i can't do pip freeze and then I won't be able to push the requirements file to heroku so that it knows what to do... – Eiyrioü von Kauyf Oct 30 '12 at 00:21
  • No, in your Linux package manager. I posted it above; sudo apt-get install python-dev –  Oct 30 '12 at 17:47
  • Yes I did that. but afterwards...? is this having the implicit assumption that they should have python-dev already installed? – Eiyrioü von Kauyf Oct 30 '12 at 22:44
  • Heroku doesn't seem to have "python-dev" Ubuntu package installed by default. – Neil Apr 20 '15 at 20:21