无法从eclipse运行/调试Django的manage.py.

时间:2011-04-06 21:09:42

标签: python django eclipse debugging

每当我尝试从Eclipse调试Django的manage.py时,我得到:

pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
Traceback (most recent call last):
  File "/proj/virtualenvs/testing/infocards/manage.py", line 15, in <module>
    execute_manager(settings)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 67, in handle
    self.run(*args, **options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/core/management/commands/runserver.py", line 76, in run
    autoreload.main(self.inner_run, args, options)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 131, in main
    reloader(main_func, args, kwargs)
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 104, in python_reloader
    reloader_thread()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 83, in reloader_thread
    ensure_echo_on()
  File "/proj/virtualenvs/testing/lib/python2.6/site-packages/django/utils/autoreload.py", line 77, in ensure_echo_on
    attr_list = termios.tcgetattr(fd)
termios.error: (22, 'Invalid argument')
Validating models...

从命令行运行python manage.py runserver可以正常工作。

Google搜索我发现termios.error: (22, 'Invalid argument')错误是因为python尝试从stdin读取但不能从Eclipse环境中读取。

[编辑]:我忘了提到我正在运行PyDev和最新的1.3版Django。

[编辑]:@Blake,@ izhak。我Eclipse我已经定义了我的virtualenv中包含的Python(/ proj / virtualenvs / testing,你可以从输出中看到)。从命令行我使用与激活virtualenv相同的Python版本。

6 个答案:

答案 0 :(得分:3)

似乎缺少--noreload会导致这种影响。怪异。

编辑:首先我认为这是项目的工作目录。

答案 1 :(得分:2)

花3个多小时来解决这个问题。 基本上罪魁祸首是django 1.3的autoload.py文件。基本上Eclipse的stdin不是tty类型的设备。 Hack解决这个问题的方法是修改/your-path-to-django/util/autoreload.py,如下所示:

index e5a421e..1a4a1a1 100644
--- a/autoreload_bak.py
+++ b/usr/local/lib/python2.6/dist-packages/django/utils/autoreload.py
@@ -73,11 +73,12 @@ def code_changed():

 def ensure_echo_on():
     if termios:
-        fd = sys.stdin.fileno()
-        attr_list = termios.tcgetattr(fd)
-        if not attr_list[3] & termios.ECHO:
-            attr_list[3] |= termios.ECHO
-            termios.tcsetattr(fd, termios.TCSANOW, attr_list) 
+        if sys.stdin.isatty():
+            fd = sys.stdin.fileno()
+            attr_list = termios.tcgetattr(fd)
+            if not attr_list[3] & termios.ECHO:
+                attr_list[3] |= termios.ECHO
+                termios.tcsetattr(fd, termios.TCSANOW, attr_list)

 def reloader_thread():
     ensure_echo_on()

这应该允许您在Eclipse中运行runserver,即使没有--noreload选项。

注意:您仍然需要应用此修补程序才能摆脱子/父进程问题,请参阅此处: How to enable Eclipse debugging features in a web application?

答案 2 :(得分:1)

当我尝试从Eclipse运行django程序时,我遇到了完全相同的错误。如果我右键单击该项目,则选择Django - &gt;自定义命令和'runserver',它会失败。我终于发现通过单击Eclipse工具栏上的“运行”按钮,它可以正常工作。尽管如此,我发现它并不总是那么肯定。我正在运行最新的PyDev,2.0。和你一样,每次都在eclipse之外的命令行运行它。

答案 3 :(得分:0)

您是否尝试过为Eclipse安装PyDev插件? Eclipse用户真的很容易开发Python应用程序,尤其是Django应用程序。只需创建新的Django项目,您就可以从项目上下文菜单中获得运行良好的环境和manage.py.

答案 4 :(得分:0)

您的系统上是否有多个版本的Python?如果从终端打开的版本与PyDev解释器使用的版本不同,则可能导致操作环境出现问题/差异。

答案 5 :(得分:0)

您可以使用Eclipse和gt; Windows&gt;首选项&gt; Pydev&gt; Python查看python版本。给出你在那里使用的确切python版本。

相关问题