1

I started using django-nose because I wanted to to run only my apps' tests via python manage.py test, but I'm running into this ImportError: no modules named urls.

This project is using Django 1.4.

The folder structure is like so:

project
├── manage.py
├── project
    ├── apps
    │   ├── app1
    |       ├── __init__.py
    │       ├── tests.py
    │   └── app2
    │   └── app3
    ├── settings.py
    ├── urls.py
    └── views.py

However, when I run python manage.py test, I get an ImportError: no module named urls:

    Traceback (most recent call last):
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 89, in get_response
    response = middleware_method(request)
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/middleware/locale.py", line 21, in process_request
    check_path = self.is_language_prefix_patterns_used()
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/middleware/locale.py", line 54, in is_language_prefix_patterns_used
    for url_pattern in get_resolver(None).url_patterns:
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 328, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/utils/importlib.py", line 38, in import_module
    __import__(name)
ImportError: No module named urls

Things I have tried that didn't work:

  1. Per the Django-nose docs, tried killing init.py from the outer project folder. This didn't change anything.
  2. Tried setting up everything in a fresh virtualenvironment.
  3. I went into importlib.py and added printed out the name, package, and sys.path:
name: project.urls
package: None
sys.path: 
‘/Users/huey/code’
‘/Users/huey/code/project’ 
‘/Users/huey/.virtualenvs/projectfresh/lib/python27.zip’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7’  
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-darwin’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-mac’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-mac/lib-scriptpackages’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-tk’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-old’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-dynload’
‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7’
‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin’
‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk'
‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac’
‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages’
‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/site-packages’
‘/Users/huey/code/project/project/apps’
‘/Users/huey/code/project/project/common’
‘/Users/huey/code/project/project/lib’

ROOT_URLCONF is 'project.urls'

I'm not sure where to go from here. Any ideas?

4

1 回答 1

1

我想到了。即使我删除了init .py,我也忘了删除其对应的 .pyc 文件。

于 2015-06-27T01:45:46.910 回答