Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Heroku Restore: Rookie Question

I am trying to create a local copy of an app that was created on Heroku that a previous developer made but abandoned. From what I see, it appears the app was created with Python/Django and Postgres (I'm more of a front-end guy so I could be missing some pieces to this).

What I've done:

I've downloaded Python, Postgres, Virtualenv and the Heroku Toolbelt. I am running the latest version of Yosemite.

Thus far, I have downloaded a PostgreSQL 9.3.6 database from Heroku Dev Center that appears to be the database file.

At this point, I'm not sure what to do with this file that appears to be named like a serial number.

My goal is to create a working local copy of this app using this Postgres file from Heroku. I'm determined to get it up and running. Any help would be greatly appreciated. Thanks.

1 Answer

Hi Seth. Yes, I ran heroku git:clone - a APP which successfully cloned my app. I'm not really sure what to do next though.

Seth Reece
Seth Reece
32,867 Points

Are you trying to load it in your browser? This is usually done with python app.py then opening the link python tells you your app is running on.

I have the Python Launcher open but I'm not sure what it is/how to configure it. I would like to get this up and running in my browser yes. How do I find the link python tells me my app is running on?

Seth Reece
Seth Reece
32,867 Points

If your trying to install Python on Mac you just let the installer do everything at default. To run your app, inside the app directory in your terminal type "python app.py" Usually app.py is the name of the main app file. If not there should be a file ending in

if __name__ == ' __main__':
  app.run()

Once your app is running it will give you a link in your terminal. Usually http://127.0.0.1:5000 i think.

I have python installed. In my app directory I see:

  • Procfile
  • insights
  • manage.py
  • ordered_model
  • ptest
  • requirements.txt

When I run python manage.py I see:

 Traceback (most recent call last):

File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/usr/local/lib/python2.7/site-packages/django/core/management/init.py", line 338, in execute_from_command_line utility.execute() File "/usr/local/lib/python2.7/site-packages/django/core/management/init.py", line 312, in execute django.setup() File "/usr/local/lib/python2.7/site-packages/django/init.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate app_config = AppConfig.create(entry) File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create module = import_module(entry) File "/usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/init.py", line 37, in import_module import(name) ImportError: No module named widget_tweaks

Seth Reece
Seth Reece
32,867 Points

Check the requirements.txt file. It should tell you any additional add-ons you need to run the app. That particular error is looking for a module named widget_tweaks. Try here: https://github.com/kmike/django-widget-tweaks

That is helpful. I've made some progress by installing all the dependencies from the requirements.txt file. The error I see now is:

% python manage.py /usr/local/lib/python2.7/site-packages/south/db/postgresql_psycopg2.py:4: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead. from django.db.backends.util import truncate_name

There is no South database module 'south.db.postgresql_psycopg2' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.

When I cloned the app it should have brought the database with it correct? Or is this a different step?

Seth Reece
Seth Reece
32,867 Points

No. The database is never included in a clone!!!!! First, it's a major security issue. Second, development and test databases should never have anything to do with production database. i.e. If you had to rebuild your production database every time you made a change during development or test, all your users would lose all their data in production! (The exclamation points aren't yelling, these are very important.) "python manage.py db init" should get your local database up.

Thanks for the clarification. I ran python manage.py db init and I received the same error:

python manage.py db init /usr/local/lib/python2.7/site-packages/south/db/postgresql_psycopg2.py:4: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead. from django.db.backends.util import truncate_name

There is no South database module 'south.db.postgresql_psycopg2' for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.

Seth Reece
Seth Reece
32,867 Points

Looks like there's a deprecation warning concerning django.db.backends.util needs to be django.db.backends.utils. There's a topic on stackoverflow concerning South in Django that might be helpful http://stackoverflow.com/questions/6172209/how-should-i-be-setting-south-database-adapters-for-my-django-app-that-uses-sout