WebFaction
Community site: login faq

I have read the other posts on WebFaction Community for this same issue, and still have not been able to solve my problem. I do have some other information that may help diagnose my problem. The exact error message I get when I browse to my Django's app URL is:

ImportError at /
No module named urls
Request Method: GET
Request URL:    http://stefanzero.com/
Django Version: 1.5.7
Exception Type: ImportError
Exception Value:    
No module named urls
Exception Location: /home/stefan0/webapps/stefanzero/lib/python2.7/django/utils/importlib.py in import_module, line 35
Python Executable:  /usr/local/bin/python
Python Version: 2.7.5
Python Path:    
['/home/stefan0/.virtualenvs/stefan_zero/lib/python2.7/site-packages',
 '/home/stefan0/webapps/stefanzero/myproject/myproject',
 '/home/stefan0/webapps/stefanzero',
 '/home/stefan0/webapps/stefanzero/myproject',
 '/home/stefan0/webapps/stefanzero/lib/python2.7',
 '/home/stefan0/lib/python2.7/pip-1.4.1-py2.7.egg',
 '/home/stefan0/lib/python2.7',
 '/usr/local/lib/python27.zip',
 '/usr/local/lib/python2.7',
 '/usr/local/lib/python2.7/plat-linux2',
 '/usr/local/lib/python2.7/lib-tk',
 '/usr/local/lib/python2.7/lib-old',
 '/usr/local/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/PIL',
 '/home/stefan0/lib/mylib']
  1. My Django web site actually works though a new WebFaction webapp with a dedicated port using python manage.py runserver portnumber. So my urls.py file is being properly imported (and so there must be no syntax error in my urls.py module). I take this to also mean that the PythonPath and sys.path are correctly set up. Furthermore, all the commands from python manage.py work properly.
  2. I then edited the httpd.conf file and specifically added the line WSGIPythonPath /home/stefan0/webapps/stefanzero/myproject/myproject which is the path to myproject.urls.py
  3. I added print statements in wsgi.py, to print out every entry in sys.path
  4. I added a try/except block in wsgi.py to test if I could import urls, and it was unable to import urls.py from within wsgi after all the necessary directories are added to sys.path
  5. I examined by logs/users/error_*.log file for clues

asked 13 May '14, 19:12

stefan0
31138
accept rate: 0%


Your python path are set up fine for shell's environment but not mod_wsgi's. They are not the same environment and you can't assume if it works in one place the paths are all fine in the other. Check the httpd.conf file's WSGIPythonPath and WSGIDaemonProcess directives and the and make sure the same paths which are defined there are also defined in shell. Use sys.path to verify this, run this in shell

>>> import sys
>>> print sys.path

Than make sure Django's error page is printing the same paths (you don't need to add them to mod_wsgi's file).

permanent link

answered 15 May '14, 04:56

johns ♦♦
5.3k212
accept rate: 23%

edited 15 May '14, 05:01

I was using os.environ[...] to set some of my variables, including the project_path. I tried serving my project locally on my MacBook Pro, and discovered that the wsgi environment didn't have the variables set from my .bash_profile (just as you said).

Therefore, I modified my Django app to read in a .txt file with these variables, and now I can successfully run my site LOCALLY with both manage.py runserver and Apache/mod_wsgi. I pushed these changes to my WebFaction account and restarted Apache for my webapp.

I also added print statements output to my Apache log file to make sure that all the required environment variables are now read in from the .txt file and their values are correct. However, I'm still getting the same import error for urls.py???

I really thought changing the way I was using the wsgi environment would fix my import problem, especially since I can now run my Django site from Apache on my MacBook. Do you have any more ideas of what I can check for problems on my WebFaction setup?

(16 May '14, 00:03) stefan0

You should set your Python search path via the python-path parameter of the WSGIDaemonProcess directive in httpd.conf, or by setting sys.path directly in your WSGI handler.

Also check that you have an __init__.py file in the directory that contains urls.py.

(16 May '14, 00:19) seanf

@seannf - Thanks for the suggestion about WSGIDaemonProcess, I will try it.

I do want to report that I found a work-around that solves my problem in the meantime. In my settings file, I changed

ROOT_URLCONF='myproject.urls'

to

ROOT_URLCONF='urls'

I did check that I have an __init__.py in my webapps/{app_name}/myproject directory, and another __init__.py in my webapps/{app_name}/myproject/myproject directory, so I don't understand why removing the package name "myproject" fixed my problem, but it did, and now I'm able to access my Django app at WebFaction over the internet.

Next, I'm trying to figure out what I'm doing wrong with my settings parameters for the django-debug-toolbar, which I have working fine when I host my site locally on my MacBook with Apache.

permanent link

answered 16 May '14, 06:30

stefan0
31138
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×903
×55
×27

question asked: 13 May '14, 19:12

question was seen: 3,972 times

last updated: 16 May '14, 06:30

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM