Skip to content

Instantly share code, notes, and snippets.

@igorkruglyak
Forked from bradtraversy/python_heroku.MD
Created August 16, 2019 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save igorkruglyak/a0d31f46d9ca7754773907f3f90ffeae to your computer and use it in GitHub Desktop.
Save igorkruglyak/a0d31f46d9ca7754773907f3f90ffeae to your computer and use it in GitHub Desktop.
Python & Postgres Heroku Deployment

Python Heroku Deployment

Steps to create a postgres database and deply a Python app to Heroku

Install guinicorn locally

pipenv install gunicorn
or
pip install gunicorn

Install Heroku CLI

https://devcenter.heroku.com/articles/heroku-cli

Login via CLI

heroku login

Create app

heroku create appname

Create database

heroku addons:create heroku-postgresql:hobby-dev --app appname

Get URI

heroku config --app appname

# Add to your app

Create Procfile

touch Procfile

# Add this
web: gunicorn app:app

Create requirements.txt

pip freeze > requirements.txt

Create runtime.txt

touch runtime.txt

# Add this
python-3.7.2

Deploy with Git

git init
git add . && git commit -m 'Deploy'
heroku git:remote -a appname
git push heroku master

Add table to remote database

heroku run python
>>> from app import db
>>> db.create_all()
>>>exit()

Visit app

heroku open
@tamecalm
Copy link

tamecalm commented Aug 16, 2019

Creating heroku-postgresql:hobby-dev on ⬢ adsvim... ⣾
(node:22785) [DEP0066] DeprecationWarning:Creating heroku-postgresql:hobby-dev on ⬢ adsvim... free
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Created postgresql-symmetrical-93636 as HEROKU_POSTGRESQL_PURPLE_URL
Use heroku addons:docs heroku-postgresql to view documentation]

I tried installing the prostgresql database see error.. Help bro

_Sent from my W2 using [FastHub](https://play.google.com/store/apps/details?id=com.fastaccess.github)_ 

@tamecalm
Copy link

That's the error given

@tamecalm
Copy link

Help sir

@igorkruglyak
Copy link
Author

@xdmahko-source
Copy link

after doing db.create_all()

/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning.
warnings.warn(FSADeprecationWarning(

db.create_all()
Traceback (most recent call last):
File "", line 1, in
File "/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 1094, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 1086, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
File "/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 1017, in get_engine
return connector.get_engine()
File "/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 594, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/app/.heroku/python/lib/python3.9/site-packages/flask_sqlalchemy/init.py", line 1027, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "", line 2, in create_engine
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned
return fn(*args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 522, in create_engine
entrypoint = u._get_entrypoint()
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/engine/url.py", line 653, in _get_entrypoint
cls = registry.load(name)
File "/app/.heroku/python/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 343, in load
raise exc.NoSuchModuleError(
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:postgres

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment