开发者

Cannot run/debug Django's manage.py from eclipse

Whenever I try to debug Django's manage.py from Eclipse I get:

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/info开发者_如何学Pythoncards/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...

Running python manage.py runserver from the command line works fine.

Googling around I found that the termios.error: (22, 'Invalid argument') error is because python is trying to read from stdin but cannot from inside the Eclipse environment.

[Edit]: I forgot to mention that I am running PyDev and the latest 1.3 version of Django.

[Edit]: @Blake, @izhak. I Eclipse I have defined the Python included in my virtualenv (/proj/virtualenvs/testing as you can see from the output). From the command line I use the same Python version as I have activated the virtualenv.


Seems like lack of --noreload causes this effect. Weird.

EDIT: First I thought it was the working directory of the project.


Spend 3+ hours figuring out this problem. Basically the culprit is with the django 1.3's autoload.py file. Basically the Eclipse's stdin is not tty type of device. the Hack to this problem is to modify /your-path-to-django/util/autoreload.py like this:

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()

This should allow you to run runserver in Eclipse even without --noreload option.

Note: You still need to apply this patch in order to get rid of child/parent process problem, see here: How to enable Eclipse debugging features in a web application?


I had the exact same error when I tried to simply run a django program from Eclipse. If I right-clicked on the project, then selected Django -> Custom Command, and 'runserver', it would fail. I finally found out that by clicking on the Run button on the Eclipse toolbar, it would work. Even there though, I've found that it's not always a sure thing. I am running the latest PyDev, 2.0. As with you, running it from the command line outside of eclipse worked every time.


Have you tryed installing PyDev plugin for Eclipse? It really makes easy for Eclipse users to develop Python apps and especially Django apps. Just create new Django project and you will get well configured environment and manage.py available for running from project context menu.


Do you have more than one version of Python on your system? If the version opened from the terminal is different that the version the PyDev interpreter is using, that could be causing problems / differences in operating environment.


Can you check in Eclipse>Windows>preferences>Pydev >Python for the python versionu u use. Give the exact python version u use there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜