ImportError:无法导入名称信号

发布于 2024-11-07 05:18:17 字数 842 浏览 4 评论 0原文

我使用 Django 1.3.0 和 Python 2.7.1。 在每次测试中,我编写以下导入,都会得到上面的导入错误:

from django.utils import unittest
from django.test.client import Client

完整的堆栈跟踪:

  File "C:\Program Files (x86)\j2ee\plugins\org.python.pydev.debug_1.6.3.2010100513\pysrc\runfiles.py", line 342, in __get_module_from_str
    mod = __import__(modname)
  File "C:/Users/benjamin/workspace/BookIt/src/BookIt/tests\basic_flow.py", line 11, in 
    from django.test.client import Client
  File "C:\Python27\lib\site-packages\django\test\__init__.py", line 5, in 
    from django.test.client import Client, RequestFactory
  File "C:\Python27\lib\site-packages\django\test\client.py", line 21, in 
    from django.test import signals
ImportError: cannot import name signals
ERROR: Module: basic_flow could not be imported.

有什么想法为什么会发生这种情况吗?

I'm using Django 1.3.0 with Python 2.7.1.
In every test I write the following imports I get the importError above:

from django.utils import unittest
from django.test.client import Client

The full stack trace:

  File "C:\Program Files (x86)\j2ee\plugins\org.python.pydev.debug_1.6.3.2010100513\pysrc\runfiles.py", line 342, in __get_module_from_str
    mod = __import__(modname)
  File "C:/Users/benjamin/workspace/BookIt/src/BookIt/tests\basic_flow.py", line 11, in 
    from django.test.client import Client
  File "C:\Python27\lib\site-packages\django\test\__init__.py", line 5, in 
    from django.test.client import Client, RequestFactory
  File "C:\Python27\lib\site-packages\django\test\client.py", line 21, in 
    from django.test import signals
ImportError: cannot import name signals
ERROR: Module: basic_flow could not be imported.

Any ideas why this happening ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怀中猫帐中妖 2024-11-14 05:18:17

@Hugo 是对的,这是一个 settings.py 问题。但我在Django环境中运行时并没有遇到这个问题。但是当我想一一运行单元测试时(通过使用 Pydev 的 run as unittest),它无法运行。
我需要做的是添加 Django 设置模块信息,所以现在我要做的是以下行添加到我的单元测试中:

from django.core import management;
import BookIt.settings as settings;
management.setup_environ(settings)

这会加载我的 Django 项目设置并允许我作为常规单元测试运行。
如果有人对如何在 Pydev 中更干净地配置它有更好的建议,请告诉我。

@Hugo was right in that it was a settings.py problem. But I didn't had that problem when running through the Django environment. But when I wanted to run unit tests one by one (By using Pydev's run as unittest) it failed to run.
What I needed to do was to add the Django settings module information, so for now what I'm doing is adding the following lines to my unit tests:

from django.core import management;
import BookIt.settings as settings;
management.setup_environ(settings)

This loads my Django project settings and allow me to run as regular unittest.
If anyone has better suggestion on how to configure this more cleanly in Pydev please let me know.

梦明 2024-11-14 05:18:17

就在一分钟前我也遇到了同样的问题。经过调查,我意识到问题出在我的 settings.py* 文件上。

检查 Django 正确查找设置文件时是否遇到问题。

这个错误信息完全是无意义的。

* IIRC Django 查找 settings.py 文件,如果没有找到,它会查找环境变量 DJANGO_SETTINGS_MODULE 并尝试。

I had the same problem just a minute ago. Investigating I realized the problem was with my settings.py* file.

Check if you are having problems with Django finding your settings file correctly.

This error message is totally non-sense.

* IIRC Django looks for settings.py file, if not found, it looks for environment variable DJANGO_SETTINGS_MODULE and try that.

成熟的代价 2024-11-14 05:18:17

这很容易解决。
如果您已经编写了settings.py(最有可能),只需导航到包含“settings.py”文件的目录并执行它。

1]蟒蛇
2]导入设置

这些命令应该可以解决问题。然后转到任意文件夹并继续执行。

This is easy to solve.
If you have already written the settings.py (most probable) just navigate into the directory which contains the "settings.py" file and execute it.

1] python
2] import settings

These commands should do the trick. Then go to any folder and continue with execution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文