Deploying to Heroku with Anaconda

前端 未结 3 717
盖世英雄少女心
盖世英雄少女心 2020-12-29 05:27

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

相关标签:
3条回答
  • 2020-12-29 05:51

    If you are in conda environment then using these steps might help to deploy your Django app to Heroku:

    Before deploying, make the following four changes to your project so it’s ready to deploy online with Heroku:

    1. Install 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 )
    2. Add 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.
    3. 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.

    4. 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.

    0 讨论(0)
  • 2020-12-29 06:01

    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.

    0 讨论(0)
  • 2020-12-29 06:05

    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:

    1. run the command "conda env export > environment.yml",
    2. open up environment.yml, and
    3. check the list for the version that corresponds to the package in question
    0 讨论(0)
提交回复
热议问题