Pycharm在django服务器上以调试模式运行时返回非asciii错误,在正常模式下运行时效果很好

问题描述 投票:0回答:1

我有相当一段时间以来在本地运行的Django服务器。今天突然我在运行调试模式下开始看到错误。它在正常模式下工作正常。

我尝试在manage.py中包含utf-8,但仍然看到错误

pydev debugger: process 10424 is connecting

Connected to pydev debugger (build 192.6603.34)
pydev debugger: process 10425 is connecting

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2066, in <module>
    main()
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2060, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1411, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1418, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python", line 1
SyntaxError: Non-ASCII character '\xcf' in file /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details```


I expect it to run on debug mode. it already bloked me 1/2 day. Please help if you already have seen this issue or know how to fix this.
debugging pycharm debug-mode
1个回答
0
投票
('sys.argv', ['/Volumes/128GB/tests/testweb/manage.py', 'runserver', '7000'])

Connected to pydev debugger (build 192.6817.19)

pydev debugger: process 19300 is connecting

('setup', {'multiproc': True, 'save-asyncio': False, 'vm_type': None, 'save-threading': False, 'save-signatures': False, 'multiprocess': False, 'module': False, 'server': False, 'client': '127.0.0.1', 'file': '/Volumes/128GB/tests/testweb/manage.py', 'DEBUG_RECORD_SOCKET_READS': False, 'cmd-line': False, 'print-in-debugger-startup': False, 'qt-support': '', 'port': 52573})



('sys.argv', ['/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py', '--port', '52573', '--client', '127.0.0.1', '--multiproc', '--file', '/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', '/Volumes/128GB/tests/testweb/manage.py', 'runserver', '7000'])

pydev debugger: process 19301 is connecting

('setup', {'multiproc': True, 'save-asyncio': False, 'vm_type': None, 'save-threading': False, 'save-signatures': False, 'multiprocess': False, 'module': False, 'server': False, 'client': '127.0.0.1', 'file': '/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', 'DEBUG_RECORD_SOCKET_READS': False, 'cmd-line': False, 'print-in-debugger-startup': False, 'qt-support': '', 'port': 52573})

  • OS:macOS 10.15.1(19B88)
  • Python:2.7.16
  • PyCharm:2019.2.3(社区版)

也是我的问题。

pydev应该将exec python脚本文件解析为“ --file” args。但是,当派生一个子进程时,它将python二进制文件添加到“ --file” args。天哪,这花费了我很多时间来解决这个问题。但是根本原因仍然没有找到。

您可以附加

args = args[1:]

以下

from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv

在PyCharm安装目录内的pydev_monkey.py文件中。这可以暂时使Debug功能正常。

例如我计算机上的/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey.py

© www.soinside.com 2019 - 2024. All rights reserved.