Forums

Second Attempt at Forking my App to PythonAnywhere: Failed again...

+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED+++FIXED

I failed at creating my first app. Being a raw noob, I gathered all the tutorials and forum posts I found and very carefully wrote down every step I followed as if doing ort of a tutorial for myself, since I plan on host with PythonAnywhere soon.

Nevertheless, I failed again. I am getting an Unhandled Exception and I cannot understand the error log:

I'd really appreciate help in trying to identify what is it that I'm doing wrong. These are my notes, 99% of it is copied from tutorials and other posts, which I though would be helpful to have in a single location:

1 Setup my environment and virtual environment

1.1 Log in to PythonAnywhere, and create a new Web app:

1.2 Go to the "Web" tab.

1.3 Select the "Add a new web app" option on the left-hand side.

1.4 If you have a Web Developer account, specify the domain you want your web app to appear on, then click "Next"

1.5 Select the "Manual configuration" option from the list.

1.6 Click "Next", and wait for the system to tell you that the web app has been created.

1.7 Check I have a web app -- go to nimbiotics.pythonanywhere.com to see the simple site that was generated.

1.8 Edit .bashrc to contain the following line:

source virtualenvwrapper.sh

1.9 Open a bash console. If you already have a bash console running, you have to source your bash by typing:

16:37 ~ $ source ~/.bashrc

1.10 Create the virtualenv:

18:23 ~/projects $ mkvirtualenv nrpccms
New python executable in nrpccms/bin/python2.7
Also creating executable in nrpccms/bin/python
Installing setuptools............done.
Installing pip...............done.

1.11 You can check it works -- the prompt should show the (nrpccms) prefix, and you can check which pip returns the virtualenv pip:

(nrpccms)20:01 ~ $ which pip
/home/nimbiotics/.virtualenvs/nrpccms/bin/pip

2 Fork project from git repository

2.1 Create Projects' folder:

(nrpccms)20:10 ~ $ cd
(nrpccms)20:10 ~ $ mkdir projects
(nrpccms)20:11 ~ $ cd projects

2.2 Fork project from git repository:

(nrpccms)20:11 ~/projects $ git clone https://github.com/nimbiotics/nrpccms
Cloning into 'nrpccms'...
remote: Counting objects: 339, done.
remote: Compressing objects: 100% (242/242), done.
remote: Total 339 (delta 80), reused 339 (delta 80)
Receiving objects: 100% (339/339), 5.64 MiB | 1.60 MiB/s, done.
Resolving deltas: 100% (80/80), done.
Checking out files: 100% (95/95), done.

3 Finish setting up your virtualenv:

(nrpccms)20:15 ~/projects/nrpccms (master)$ cd
(nrpccms)20:15 ~ $ cdproject
(nrpccms)20:15 ~/projects/nrpccms (master)$

3.1 Check your virtualenv's project folder is working :

(nrpccms)20:15 ~/projects/nrpccms (master)$ cd
(nrpccms)20:15 ~ $ cdproject

3.2 Install your project's requirements:

(nrpccms)20:15 ~/projects/nrpccms (master)$ pip install -r requirements/requirements.txt

4 Static files

Because we had to use manual web app creation to use this virtualenv (instead of PythonAnywhere's built-in Django web app quick-start option, which you'll remember uses an older version of Django), one thing is missing: Configuration for static file mappings.

4.1 To fix this, go to the "Web" tab, select your domain at the left if it's not already selected, then in the "Static files" table:

4.2 Click on the "Enter URL" and enter /static/admin/, then hit return.

4.3 Click on the "Enter path" on the same line, and enter /home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/site-packages/django/contrib/admin/static/admin

4.4 Click on the "Enter URL" and enter /static/, then hit return.

4.5 Click on the "Enter path" on the same line, and enter /home/nimbiotics/.projects/nrpccms/static/

4.6 Edit urls.py. Uncomment the admin lines if you need to, but most importantly use staticfiles_urlpatterns to serve static pages. Your urls.py should read something like this:

from django.conf.urls.defaults import patterns, include, url

from django.contrib import admin
admin.autodiscover()

# Admin interface
# ---------------
urlpatterns = patterns('',
# [EG] url(r'^<my project name>/', include('<my project name>.foo.urls')),
url(r'^admin/', include(admin.site.urls)),
)

# HOMEPAGE FOR A BLOG-ONLY SITE
# -----------------------------
# My case!
url("^$", "mezzanine.blog.views.blog_post_list", name="home"),

# MEZZANINE'S URLS
# ----------------
("^", include("mezzanine.urls")),

# Error pages
# -----------
handler404 = "mezzanine.core.views.page_not_found"
handler500 = "mezzanine.core.views.server_error"

# This is needed to serve static files like images and css
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()

5 WSGI

5.1 From PythonAnywhere->Dahsboard->Web, click on the link that contains your wsgi configuration; the link right next to “It is configured via a WSGI file stored at:” and edit it to look like below. The most important thing to remembert here is that path has to point to nrpccms's parent directory

import os
import sys

path = '/home/nimbiotics/projects'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'nrpccms.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

6 The database

Because of the way PythonAnywhere serves its files; a MySQL database will get served faster than a sqlite3 database, so here we go.

6.1 Create db nrpccms in “PythonAnywhere->Dashboard->Databases”

6.2 Edit your settings.py so DATABASES contains your db credentials:

# ...
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "nimbiotics$nrpccms",
        "USER": "nimbiotics",
        "PASSWORD": "***MYSQL_PASSWORD***",
        "HOST": "mysql.server",
        "PORT": "",
    }
}
# ...

6.3 Create your database in the console:

(nrpccms)18:55 ~/projects/nrpccms (master)$ ./manage.py createdb

OK, looking forward to seeing the notes. From a quick look at your error log, my guess is that it's something to do with a clash between your configuration and the Mezzanine version -- but that is only a guess.

I don't get along with ANY markup language ...

Glen: I'm not sure what you mean by "a clash between your configuration and the Mezzanine version" ... This is working on my PC where I have a 100% OOB python installation and almost everything needed by my app I had to install WITHIN my virtualenv. BTW, this is my requirements.txt:

Django==1.5.4
Mezzanine==1.4.16
MySQL-python==1.2.4
Pillow==2.2.1
South==0.8.2
Werkzeug==0.9.4
argparse==1.2.1
bleach==1.2.2
django-appconf==0.6
django-compressor==1.3
django-extensions==1.2.2
filebrowser-safe==0.2.28
grappelli-safe==0.2.22
html5lib==0.95
mezzanine-slides==1.0.3
oauthlib==0.6.0
psycopg2==2.5.1
pytz==2013.7
requests==1.2.3
requests-oauthlib==0.3.3
six==1.4.1
wsgiref==0.1.2
yolk==0.4.3

Are you activating the virtualenv in your WSGI file? Look at the activate_this bits at the top of the WSGI file in the how-to guide on our wiki:

https://www.pythonanywhere.com/wiki/VirtualEnvForNewerDjango

Thanks Harry;

I was indeed working with the wrong wsgi.py file ... mind you, (WSGI Configuration for Django 1.5)[https://www.pythonanywhere.com/forums/topic/911/] IS one of my sources ...

This is my wsgi.py now:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#! python
activate_this = '/home/nimbiotics/.virtualenvs/nrpccms/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

path = '/home/nimbiotics/projects'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'nrpccms.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

NEVERTHELESS, I'm still getting the very same error ...

Did you do a "reload web app"?

Yes I did

I couldn't actually find the activate_this code in your WSGI file (which is at /var/www/nimbiotics_pythonanywhere_com_wsgi.py). I've added it for you, now you have a different error. I think it's to do with a missing package in your virtualenv. What do you think?

Thanks again Harry

Please allow me to remind you I'm just an old fart db apps programmer giving my very first baby steps all in python, web development and PythonAnywhere.

That said; You just made me go thru another "duh!" moment: I did edit my wsgi file, BUT the one in my projects folder. Thanks a lot for pointing this one out.

As for the the "No module named newsroom" error: The module's code is there and the module is also the very first one in INSTALLED_APPS, so I don't know what else to look for. It is being added just as "newsroom": Should I use "nrpccms.newsroom"?

TIA!!

Harry;

I did fully identify newsroom as nrpccms.newsroom and could finaly get past the unhandled error.

I'm now getting an error which I understand even less: 'blog_extras' is not a valid tag library: ImportError raised loading nrpccms.newsroom.templatetags.blog_extras: No module named settings

I understand my previous issues had nothing with development but with deployment. This new issue seems to be development related and, since I have not seen this error in my development environment it puzzles me even more.

Why is it asking me for a module named settings? what am I to put in it? where is it supposed to live at?

TIA!

When I see things lie this in the same file:

path = '/home/nimbiotics/projects/nrpccms'

and

os.environ['DJANGO_SETTINGS_MODULE'] = 'nrpccms.settings'

it makes me think that perhaps your pathing is wrong. If you have /home/nimbiotics/projects/nrpcms on your path and nrpcms.settings for your Django settings module, that means you need a settings.py at /home/nimbiotics/projects/nrpcms/nrpcms/settings.py Note the double nrpcms in the path

Glenn: I have already fixed that, just forgot to report it here as I have been trying things I've been reading here and there; none of them worked.

As I said in my last post; after changing newsroom to nrpccms.newsroom in my INSTALLED_APPS, my app did go past the unhandled error to give me "ImportError raised loading nrpccms.newsroom.templatetags.blog_extras: No module named settings"

Again, nrpccms.newsroom is my first app in INSTALLED_APPS and also the path to nrpccms/settings.py is the second item in sys.path:

'/home/nimbiotics/projects'
'/home/nimbiotics/projects/nrpccms'
'/home/nimbiotics/.virtualenvs/nrpccms/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg'
'/home/nimbiotics/.virtualenvs/nrpccms/local/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg'
'/home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7'
'/home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/plat-x86_64-linux-gnu'
'/home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/lib-tk'
'/home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/lib-old'
'/home/nimbiotics/.virtualenvs/nrpccms/lib/python2.7/lib-dynload'
'/usr/lib/python2.7'
'/usr/lib/python2.7/plat-x86_64-linux-gnu'
'/usr/lib/python2.7/lib-tk'
'/home/nimbiotics/.virtualenvs/nrpccms/local/lib/python2.7/site-packages'

I don't know what else to look for...

In that case, the error can also be caused by syntax errors in your settings.py. You can either try a manage.py shell or python -c "import settings" in your app directory to see if you get any errors.

I just imported settings without problems ... this is driving me nuts and I'm almost sure its gonna end up being a stupid thing I forgot or messed up with

Fixed: I had to add my projects folder to sys.path in my wsgi script. This is my new wsgi script:

activate_this = '/home/nimbiotics/.virtualenvs/nrpccms/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

import os
import sys

path = '/home/nimbiotics/projects'
if path not in sys.path:
    sys.path.append(path)

###########################################################
nrpccms_path = '/home/nimbiotics/projects/nrpccms'
if nrpccms_path not in sys.path:
    sys.path.append(nrpccms_path)
###########################################################

os.environ['DJANGO_SETTINGS_MODULE'] = 'nrpccms.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Wow, thanks for all of the details! Hopefully this will help out anyone else encountering the same problems.