ece651-winter2019 / ece651-group-project

Simple web application that takes patient heart rate info and provides an interface for health practitioners to view patients data. This toy project can be re-purposed for any simple multi user, data collection application. Implements a rest api and accompanying mobile application.
https://pyramid-backend.herokuapp.com/
4 stars 4 forks source link

Heroku cannot use mysql + sqlalchemy on dyno #49

Closed adkulas closed 5 years ago

adkulas commented 5 years ago

In order to run sqlalchemy with mysql you need to install the python package pip install mysqlclient. This package requires a linux dependency installed using sudo apt install default-libmysqlclient-dev.

The problem is dynos do not allow the installation of additional linux packages. I believe the solution will be to create a docker image and deploy the image on heroku. Or we must look for another deployment method.

2019-02-27T04:03:05.592208+00:00 app[web.1]: Complete output from command python setup.py egg_info:
2019-02-27T04:03:05.592487+00:00 app[web.1]: /bin/sh: 1: mysql_config: not found
2019-02-27T04:03:05.592490+00:00 app[web.1]: Traceback (most recent call last):
2019-02-27T04:03:05.592492+00:00 app[web.1]: File "<string>", line 1, in <module>
2019-02-27T04:03:05.592494+00:00 app[web.1]: File "/tmp/pip-install-603mes3n/mysqlclient/setup.py", line 16, in <module>
2019-02-27T04:03:05.592495+00:00 app[web.1]: metadata, options = get_config()
2019-02-27T04:03:05.592497+00:00 app[web.1]: File "/tmp/pip-install-603mes3n/mysqlclient/setup_posix.py", line 51, in get_config
2019-02-27T04:03:05.592499+00:00 app[web.1]: libs = mysql_config("libs")
2019-02-27T04:03:05.592500+00:00 app[web.1]: File "/tmp/pip-install-603mes3n/mysqlclient/setup_posix.py", line 29, in mysql_config
2019-02-27T04:03:05.592502+00:00 app[web.1]: raise EnvironmentError("%s not found" % (_mysql_config_path,))
2019-02-27T04:03:05.592504+00:00 app[web.1]: OSError: mysql_config not found
2019-02-27T04:03:05.592506+00:00 app[web.1]: 
2019-02-27T04:03:05.592509+00:00 app[web.1]: ----------------------------------------
2019-02-27T04:03:05.676513+00:00 app[web.1]: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-603mes3n/mysqlclient/
2019-02-27T04:03:05.797139+00:00 heroku[web.1]: Process exited with status 1
2019-02-27T04:03:05.812883+00:00 heroku[web.1]: State changed from starting to crashed
gaberch commented 5 years ago

I wonder if having to install default-libmysqlclient-dev and mysqlclient is the only way to connect to mysql. There are django apps out there that having been deployed with MySQL databases. I'm going to look for potential pyramid with MySQL database examples deployed to Heroku to see if there's a workaround. I don't want to go down the docker route just yet. I had a lot of issues with it previously and I'd rather see if there's a simple fix to this before I take on that beast again.

gaberch commented 5 years ago

Ok so there may be a workaround. There is an alternative way to connect to the database using mysqlclient. The alternative option is mysql-connector-python. There doesn't seem to be a linux dependency needed for it so we we might be in the clear with using the dyno.

adkulas commented 5 years ago

The django apps that work use the djagno ORM so sqlalchemy isnt involved. @jmcarrillog prefers django because hes finding more resources on the framework. Should we consider switching?

gaberch commented 5 years ago

There's a heck of a lot more documentation for django deployments on Heroku as well. I'm all for switching to it.

ammarahmed93 commented 5 years ago

@adkulas I am actually using "mysql-connector-python" instead of "mysqlclient".

adkulas commented 5 years ago

bad news... django also requires the same mysql driver

  File "/home/calkulas/Documents/ECE651/ece651-group-project/healthapp_project/env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
    ) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
[2019-02-27 22:18:26 +0000] [19969] [INFO] Worker exiting (pid: 19969)
[2019-02-27 17:18:26 -0500] [19966] [INFO] Shutting down: Master
[2019-02-27 17:18:26 -0500] [19966] [INFO] Reason: Worker failed to boot.

I'm really not interested in trying to find workarounds for this since it's taking a lot of time. What does everyone think of switching to postgres to avoid these problems?

gaberch commented 5 years ago

@ammarahmed93 is this something doable for you in a very short amount of time? Do you have to backtrack a lot to make this work?

ammarahmed93 commented 5 years ago

@gaberch I don't think it would be doable with the time we got. I have never worked with Django ORM so it will be a learning curve and I am assuming it would require a lot of time reading, troubleshooting, and if not writing a whole new code from scratch.

adkulas commented 5 years ago

@gaberch @ammarahmed93 im currently looking into docker to bypass the dependency problem

gaberch commented 5 years ago

@adkulas I would suggest looking into the documentation for the ClearDB add-on for Heroku. There's documentation on it for how to use it with a Django app. Maybe they have something there to bypass this problem since ClearDB is meant for MySQL and they say it works with Django. https://devcenter.heroku.com/articles/cleardb#using-cleardb-with-python-django

I don't think we need to use Docker to solve this issue.

adkulas commented 5 years ago

Looked into the difference between mysqlclient and mysql-connector-python and found these

https://stackoverflow.com/questions/26573984/django-how-to-install-mysql-connector-python-with-pip3 https://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html

The mysql-connector-python is written in pure python. Going to try that and see if it connects