Django Nose ImportError: no modules named urls

Django Nose ImportError: no modules named urls

我开始使用 django-nose 是因为我想 运行 通过 python manage.py 测试只对我的应用程序进行测试,但我 运行 正在进入这个 ImportError: 没有名为 urls 的模块。

这个项目使用的是 Django 1.4。

文件夹结构如下:

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

但是,当我 运行 python manage.py 测试时,我得到一个 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

我尝试过但无效的方法:

  1. 根据 Django-nose 文档,尝试从外部项目文件夹中删除 init.py。这并没有改变任何东西。
  2. 尝试在全新的虚拟环境中设置所有内容。
  3. 我进入 importlib.py 并添加打印出名称、包裹和 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 是 'project.urls'

我不确定从这里到哪里去。有什么想法吗?

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