Saturday, April 19, 2014

Managing Multiple Versions of Python with pyenv

I have been recently working on a project that needed to be tested on multiple versions of Python.  I found pyenv to be invaluable:

https://github.com/yyuu/pyenv

This project was apparently forked rbenv and ruby-build and works about the same.

I also found this article useful:

http://dtucker.co.uk/hack/installing-pyenv-on-mac-osx.html

Python + Gmail = Email Adventures!

Today I learned how to send email using Gmail as a service provider.  I learned from reading this thread:

http://stackoverflow.com/questions/10147455/trying-to-send-email-gmail-as-mail-provider-using-python

Sunday, April 6, 2014

Location of bower_components directory in AngularJS phone tutorial

I'm actually enjoying the Angular JS tutorial: http://docs.angularjs.org/tutorial

However, I have a sneaking suspicion that the bower_components directory should be located on the same level as the app directory (not inside of it).

christohersmbp2:angular-phonecat christopherspears$ ll | awk '{print $9}'

LICENSE
README.md
app/
bower.json
bower_components/ <- moved it here
node_modules/
npm-debug.log
package.json
scripts/

test/

Am I wrong?

Sunday, March 30, 2014

Location of the Procfile

Keep your Procfile in your project's top directory!  Otherwise, gunicorn (the server running your app) will not be able to see the Procfile!


/Users/christopherspears/PyDevel/tapeworm_django/
Procfile
README.md
requirements.txt
tapeworm/
  __init__.py
  __init__.pyc
  drawings/
  manage.py
  tapeworm/
  templates/

Friday, March 28, 2014

Deploying a Python Django app to Heroku

Today I decided to try to deploy my app to Heroku.  Fortunately, I found a pretty good tutorial that shows me how to do this:

https://devcenter.heroku.com/articles/getting-started-with-django

I will be detailing my trials and tribulations as I attempt to do this.  My first issue was that I could not get foreman to work.  The gem foreman is not part of the django-toolbelt.  It is part of the Heroku ToolBelt.  I fixed this by uninstalling and reinstalling the gem.  I then discovered that the Procfile I created needed to be at the same level as the manage.py file.  Otherwise, I would get a bunch of this:

(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ foreman start
11:18:52 web.1  | started with pid 2122
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Starting gunicorn 18.0
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Listening at: http://0.0.0.0:5000 (2122)
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Using worker: sync
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [INFO] Booting worker with pid: 2125
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [ERROR] Exception in worker process:
11:18:52 web.1  | Traceback (most recent call last):
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
11:18:52 web.1  |     worker.init_process()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
11:18:52 web.1  |     self.wsgi = self.app.wsgi()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
11:18:52 web.1  |     self.callable = self.load()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
11:18:52 web.1  |     return self.load_wsgiapp()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
11:18:52 web.1  |     return util.import_app(self.app_uri)
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
11:18:52 web.1  |     __import__(module)
11:18:52 web.1  | ImportError: No module named tapeworm.wsgi
11:18:52 web.1  | Traceback (most recent call last):
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
11:18:52 web.1  |     worker.init_process()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
11:18:52 web.1  |     self.wsgi = self.app.wsgi()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
11:18:52 web.1  |     self.callable = self.load()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
11:18:52 web.1  |     return self.load_wsgiapp()
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
11:18:52 web.1  |     return util.import_app(self.app_uri)
11:18:52 web.1  |   File "/Users/christopherspears/.virtualenvs/tapeworm_django/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
11:18:52 web.1  |     __import__(module)
11:18:52 web.1  | ImportError: No module named tapeworm.wsgi
11:18:52 web.1  | 2014-03-28 11:18:52 [2125] [INFO] Worker exiting (pid: 2125)
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Shutting down: Master
11:18:52 web.1  | 2014-03-28 11:18:52 [2122] [INFO] Reason: Worker failed to boot.
11:18:52 web.1  | exited with code 3

11:18:52 system | sending SIGTERM to all processes

By the way, I always forget to do this when creating a Heroku app:

(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ heroku apps:create tapeworm
Creating tapeworm... done, stack is cedar
http://tapeworm.herokuapp.com/ | git@heroku.com:tapeworm.git
Git remote heroku added

Otherwise, Heroku is going to give your app a name like "Flowing Downstream Leaves", which is annoying.  I managed to successfully push my app to Heroku.  The next step is to try to turn it on.

Wednesday, March 26, 2014

Django Json Field

Been looking for a good json field for Django.  I hope this will work:

https://github.com/bradjasper/django-jsonfield

Creating a requirements.txt file

You can create a requirements.txt file for a Python project with pip:
(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ pip freeze > requirements.txt
(tapeworm_django)christohersmbp2:tapeworm_django christopherspears$ cat requirements.txt 
Django==1.6.2
psycopg2==2.5.2

wsgiref==0.1.2