Error on importing file

software development


I’m currently trying to set up a Django project using passenger wsgi. I followed the instructions laid out on this post:

However, I’m receiving an error “An error occurred importing your”

I am able to successfully receive a hello word message if I put this as my

def application(environ, start_response): start_response('200 OK', [('Content-type', 'text/plain')]) return ["Hello, world!"]

But for some reason if I use the following (outlined in the above post), I am unable to get past the error. I replace the word ‘project’ with my named project on the path.append and os.environ lines and with on the path.insert lines. Am I missing something? I am very new to this stuff and would appreciate any help I can get! Thanks.

Below is the current that receives the error on importing.

[code]import sys, os
cwd = os.getcwd()
sys.path.append(cwd + ‘/project’)

if sys.version < “2.7.3”: os.execl("$HOME//env/bin/python",
“python2.7.3”, *sys.argv)


os.environ[‘DJANGO_SETTINGS_MODULE’] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()[/code]


Assuming that everything except is literal: $HOME only works in the shell. You will need to expand that to the actual path to your home directory in all instances.

Also: I see that you’re trying to exec Python 2.7.3. You do have that installed in your home directory, right?


Thanks for responding… I was able to fix the problem by changing from $HOME and yes I do have Python 2.7.3 on a virtualenv. However, I’m now getting a 500 error.

Here is what my current file looks like, it no longer gets the importing error:

[code]import sys, os
sys.path.append(os.path.join(os.getcwd(), ‘project’))

sys.path.insert(0, ‘home//env/bin’)
sys.path.insert(0, ‘home//env/lib/python2.7/site- packages/django’)
sys.path.insert(0, ‘home//env/lib/python2.7/site-packages’)
sys.path.insert(0, ‘home//roommates’)

os.environ[‘DJANGO_SETTINGS_MODULE’] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()[/code]

The error that shows up in the error log is as follows:

Premature end of script headers: Premature end of script headers: internal_error.html

Any idea on how to continue?


Hmm, that still doesn’t look right (unless you’ve just messed up sanitizing the paths). I’d expect the correct path lines to look something like:

You also shouldn’t be inserting both site-packages and site-packages/django — that’ll cause some really weird behavior with relative imports.

Also: Do you have MySQLdb installed in your virtualenv?


Would removing those paths help? I don’t have much experience with this so I was just copy pasting from the guide I linked. I did run into the issue with MySQLdb not being installed and I believe it is successfully installed now on the virtualenv.