Heroku Django 배포시 "No module Error" 해결

geunyeongii·2022년 10월 21일
0

Django 프로젝트 내에서 Procfile 과 settings.py, runtime.txt를 작업한 뒤 heroku CLI를 통해서 배포를 진행했는데 계속 django Module을 찾지 못했다.

이를 해결하기 위해 heroku 내 앱의 console의 bash를 이용해 pip list를 확인해봤지만 로컬에있는 것들이 어째서인지 완벽하게 안 들어가있는 것이었다.

결국은 Pipenv환경 파일을 모두 없애고 Procfile에 코드 두 줄을 넣고나서야 해결이 됐다!!

삽질

계속 gunicorn이 인식이 안된다고 해서 계속 여러가지 시도를 해봤지만,

2022-10-21T12:27:20.502419+00:00 app[web.1]: ModuleNotFoundError: No module named django
2022-10-21T12:27:20.502433+00:00 app[web.1]:
2022-10-21T12:27:20.502433+00:00 app[web.1]: The above exception was the direct cause of the following exception:
2022-10-21T12:27:20.502434+00:00 app[web.1]:
2022-10-21T12:27:20.502447+00:00 app[web.1]: Traceback (most recent call last):
2022-10-21T12:27:20.502462+00:00 app[web.1]: File"/app/manage.py"', line 22, in <module>
2022-10-21T12:27:20.502573+00:00 app[web.1]: main(
2022-10-21T12:27:20.502588+00:00 app[web. 1]: File"/app/manage.py", line 13, in main
2022-10-21T12:27:20.502686+00:00 app[web.1]: raise ImportError
2022-10-21T12:27:20.502738+00:00 app[web. 1]: ImportError: Couldn't import Django. Are you sure it'"s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
2022-10-21T12:27:20.678844+00:00 heroku[web.1]: Process exited with status 1
2022-10-21T12:27:20.865312+00:00 heroku[web.1]: State changed from starting to crashed
2022-10-21T12:27:23.000000+00:00 app[api]: Build succeeded
2022-10-21T12:27:59.607046+00:00 heroku[router]: at=error code=H10 desc="App crashed method=GET path="/" host=django-web-kdt-ai.herokuapp.com request_id=4edab2a4-81c34da5-80f5-10685f833c22 fwd="182.218.200.213" dyno= connect=service=status=503 byte= protocol=https

그냥 아예 서버내에 django 모듈이 설치가 안됐던 것이다.

/app/manage.py 를 찾지 못하는 에러가 주변에 여러명도 같은 경험을 하고있는 중이었다.

마침 Pipfile을 지워보라는 글을 보고 바로 지워보니 requirements.txt가 제대로 작동했다!
Pipenv 환경을 모두 제거해줬지만 배포는 되고 웹페이지를 뿌려주지 못하고있었다.

2022-10-21T16:02:57.639920+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2022-10-21T16:02:57.780189+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-10-21T16:02:57.963561+00:00 heroku[web.1]: Process exited with status 137
2022-10-21T16:02:58.424134+00:00 heroku[web.1]: State changed from starting to crashed

또 이런 에러가 났다.

열심히 찾던 중 공식문서에서 대충 포트에 문제가 있는 것 같았다.

계속 이분들과 같은 말을 하는 사람이 많았았다.
그래서 시도 해보기로 했다.

바로 Procfile에 runserver에 $PORT를 붙여줬더니 된다.....

# Procfile
web: gunicorn webproj.wsgi --log-file -
web: python manage.py runserver 0.0.0.0:$PORT

결국 성공! 이 에러에 10시간을 썼던 것 같다....
이걸로 하루를 다 버린 것 같다....

profile
✏️세상의 모든 기록 ✏️

0개의 댓글