> For the complete documentation index, see [llms.txt](https://bloomtechlabs.gitbook.io/ds-bw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bloomtechlabs.gitbook.io/ds-bw/units-3-and-4/tensorflow-on-heroku.md).

# TensorFlow on Heroku

*Follow this advice if you want to use TensorFlow on Heroku!*

[Tomás Phillips](https://app.slack.com/team/W017UEA709J)\
[@Nathan McDonough](https://lambda-students.slack.com/team/W0196UK1DD3) and I dealt with a lot of errors and troubleshooting today, but we were finally able to deploy a neural network model onto Heroku! To those of you that are doing the same, these three fixes did the trick:

1. Using pipenv with Heroku causes Heroku to use an outdated version of pip, and thus not being able to install tensorflow. We needed to run the command `pip freeze > requirements.txt`  while in a pipenv shell in the root directory in order to write all dependencies into a `requirements.txt` file. Then, we deleted `Pipfile`  and `Pipfile.lock`.
2. We created a `runtime.txt`  file in order to record what version of python we were using. For example, in the file all we needed to write was `python-3.8.6`
3. Finally, the tensorflow library ended up being too large for Heroku. I saw somewhere that the library is 420M in size, and Heroku has a cap at 500M. In the `requirements.txt` , we needed to change `tensorflow`  to `tensorflow-cpu` . Tensorflow-cpu is a version of tensorflow that uses the cpu instead of the gpu, and this is ok, because the model will still work and Heroku doesn't even have gpu capabilities. The tensorflow-cpu library ended up being \~200M smaller than the standard tensorflow library.
4. And voila! After hours of troubleshooting, the model is deployed!\
   \
   [Ben Somerville](https://app.slack.com/team/W0198A6DUTC)\
   Maybe it was just me but I recommend using tensorflow-cpu 2.3.1!! Not 2.4! Had some very mysterious issues which heroku logs gave me absolutely no details on. It came down to that. Not sure if it's 100% necessary, but definitely worth trying if one is running into trouble.
