[Django]-What do I add to my requirements.txt in Django directory in order to push it to Heroku?

7👍

✅

The problem is, that python2.7 and python3.x are different versions. You need the same version of python – server and local.

ToDos:

  1. Take the terminal an go to the project directory

    cd /your/path/to/project/

  2. Activate your virtualenv

    source env/bin/activate

  3. Generate requirements.txt with pip

    pip freeze > requirements.txt

  4. Go to your server and create new virtualenv with same python version (https://virtualenv.pypa.io/en/stable/reference/#cmdoption-p)

    virtualenv –python=python2.7 env

  5. Activate virtualenv on server

    source env/bin/activate

  6. Install requirements.txt with pip

    pip install -r requirements.txt

  7. Django migrations

    python manage.py migrate

  8. Start django with runserver (to test) or connect webserver (nginx, uwsgi, gunicorn, …)

    python manage.py runserver

8👍

Inside your Python virtual environment and in your project path, just type:

pip freeze > requirements.txt.

This will list inside the requirements.txt file the exact version of each python package you use. And that’s how Heroku will know what packages it needs to install in order to run your Django app.

Leave a comment