I am trying to deploy my Flask Api on heroku but I am always getting the error
Compressing... ! Compiled slug size: 950.5M is too large (max is 500M). ! See: http://devcenter.heroku.com/articles/slug-size ! Push failed
The only files I have are app.py, requirements,txt, Procfile and .gitignore(it only contains pycache)
This is my requirements.txt file :
albumentations==1.1.0
Flask==2.1.2
flask_marshmallow==0.14.0
Flask_SQLAlchemy==2.5.1
numpy==1.22.3
opencv_python_headless==4.5.5.64
pandas==1.4.2
SQLAlchemy==1.4.39
SQLAlchemy_Utils==0.38.2
timm==0.5.4
torch==1.11.0
Werkzeug==2.1.2
gunicorn==19.9.0
Please suggest what I should do. I tried all the methods available on Google and stackoverflow for almost 2 days but in vain. There is no issue with the buildpacks. It is correct.
CodePudding user response:
You are using very large dependencies. Pandas, OpenCV, torch and numpy all have very large wheels and that doesn't include their dependencies. All of those dependencies end up as part of your slug. That's why Heroku is complaining.
Try creating a local virtual environment and install these dependencies one by one while monitoring the size.
python3 -m venv test-venv
source test-venv/bin/activate
du -sh test-venv # before pandas
pip install pandas
du -sh test-venv # after pandas