I have a Django app I want to deploy to Heroku. I tried to follow the instructions here: https://devcenter.heroku.com/articles/getting-started-with-django which tells you to
Before deploying, make the following four changes to your project so it’s ready to deploy online with Heroku:
gunicorn
as your web-server.
( Since, you are using conda environment gunicorn is not currently available at any conda channels to install. So, use pip install gunicorn
) requirements.txt
file to your project's base directory and inside it add the modules names along with it versions or simply copy the contents that you get after you run pip freeze
command. Make a new file: Procfile
& inside it add the following:
web: gunicorn [Project_name].wsgi --log-file -
(Here [Project_name]
is your own project's directory name)
This says to use your existing [Project_name].wsgi file but with gunicorn.
Make just a single change to settings.py
file:
ALLOWED_HOSTS = ['*']
( The wildcard Asterisk * means all domains are acceptable to keep things simple. )
Now finally you can deploy using these steps:
Create a new app on Heroku:
On CLI type heroku create
(Heroku will create a random name for your app; [your_app_name])
Add a git remote “hook” for Heroku:
heroku git:remote -a [your_app_name]
Ignore static files:
heroku config:set DISABLE_COLLECTSTATIC=1
Push our code to Heroku:
git push heroku master
Finally, make your Heroku app live:
heroku ps:scale web=1
( Here, web=1
for basic Heroku services )
To open your app: heroku open
Your app should now be live on Heroku.
I had this problem too.
I wanted to deploy a django app which use numpy, sckit-learn and some other conda packages.
I used the conda-buildpack but the installed packages weren't accessible from inside django. So I created a fork which extended the PYTHONPATH
and removed the part where dependencies installed withpip install -r requirements.txt
because this part clashed with memcached on heroku.
Now I have a multiple buildpack setup
with the default heroku python buildpack and my custom condas buildpack fork
The requirements.txt
is processed by the python buildpack and the conda-requirements.txt
by the conda buildpack. Works like a charm for me.
I was able to deploy using Firebolt's method, with the following modifications:
On step 2: when adding the requirements.txt file to the project base directory, if you are copying the contents of the pip freeze command, you will have to replace any references to file paths with the version of the package.
example: replace "asgiref @ file:///tmp/build/80754af9/asgiref_1602513567813/work" with "asgiref==3.3.0".
In order to check which version of the package to install: