1

I'm new to Flask and heroku but I built a simple app and pushed it to heroku using SQLite. After migrating the app to a remote mysql db I noticed that can't get the app running because I'm getting the following error:

ImportError: No module named MySQLdb

After searching around I found that this error is because I need to install pip install mysql-python

However, my requirements.txt file already contains mysql-python

$ pip freeze

Flask==0.10.1
Flask-Login==0.3.2
Flask-Migrate==1.6.0
Flask-SQLAlchemy==2.1
Flask-Script==2.0.5
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23

MySQL-python==1.2.5

PyYAML==3.11
SQLAlchemy==1.0.9
Werkzeug==0.10.4
...

When I run bash on heroku it says that I've already met the requirements:

~ $ heroku run bash
Running bash on blank-places-7646... up, run.9708

~ $ pip install mysql-python
Requirement already satisfied (use --upgrade to upgrade): mysql-python in ./.heroku/python/lib/python2.7/site-packages

~ $ pip freeze
alembic==0.8.3
Flask==0.10.1
Flask-Login==0.3.2
Flask-Migrate==1.6.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23
MySQL-python==1.2.5
pbr==1.8.1
python-editor==0.4
SQLAlchemy==1.0.9
stevedore==1.9.0
Werkzeug==0.10.4

~ $ pip install mysql-python --upgrade
Requirement already up-to-date: mysql-python in ./.heroku/python/lib/python2.7/site-packages

Where am I going wrong?

Community
  • 1
  • 1
shartshooter
  • 1,761
  • 5
  • 19
  • 40
  • How are you running The app? It seems that you are not installing the package on the same Python you are trying to run the app. The default database of heroku is PostgreSQL. And for my [expirience]( http://stackoverflow.com/questions/33180337/flask-sql-alchemy-mysql-multiple-foreign-keys-issues) and a lot of [people] (http://grimoire.ca/mysql/choose-something-else) MySQL sucks. Try that – CESCO Nov 07 '15 at 16:20
  • Heroku recognizes apps automatically(https://devcenter.heroku.com/articles/getting-started-with-python-o) but shouldn't I be able to use any db I want? – shartshooter Nov 07 '15 at 18:38
  • I think that Postgres comes out of the box. To use MySQL you need an addon plugin that might be paid. I don't know you need to check it. Run 'heroku config' to check if you haven't already got a Postgres db running on your server. I essentially use heroku with JAVA. At least that's how it goes in the Java world. – CESCO Nov 07 '15 at 18:43
  • It recognizes the language, not the db btw. – CESCO Nov 07 '15 at 18:44

2 Answers2

0

MySQL is an addon on Heroku so try installing ClearDB.

heroku addons:add cleardb

https://elements.heroku.com/addons/cleardb

Steve
  • 1,423
  • 10
  • 13
0

What worked for me: I moved the MySQL connection to a separate file and did my calculations there. Returned the results to the main routes file as a json.

I suspect that heroku doens't all MySQL connections in the same file where you have routing set up.

Rohit Mittal
  • 1
  • 1
  • 2