【问题标题】:Pycharm returns non-asciii error on running in django server in debug mode, works fine when I run in normal modePycharm 在调试模式下在 django 服务器中运行时返回非 asciii 错误,当我在正常模式下运行时工作正常
【发布时间】:2021-03-19 19:06:42
【问题描述】:

我有相当长一段时间以来一直在本地运行 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.

【问题讨论】:

  • 我也尝试并重新安装了 pycharm。我不知道这个非ascii字符在哪里

标签: debugging pycharm debug-mode


【解决方案1】:
('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})

  • 操作系统:macOS 10.15.1 (19B88)
  • Python:2.7.16
  • PyCharm:2019.2.3(社区版)

也是我的问题。

pydev 应该将 exec python 脚本文件解析为“--file”参数。但是当 fork 一个子进程时,它会将 python 二进制文件添加到“--file”参数中。
天哪,它浪费了我很多时间来处理这个问题。但还是没有找到根本原因。

你可以追加

args = args[1:]

下面

from _pydevd_bundle.pydevd_command_line_handling import setup_to_argv

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

例如/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey.py 在我的电脑上。

【讨论】:

    【解决方案2】:

    尝试使用 noreload 运行,因为 pydev 尝试将 python 可执行文件解释为脚本,所以在产生子进程的 autoreloader 时似乎失败了

    【讨论】:

      【解决方案3】:

      使用 noreload 运行可以解决“SyntaxError: Non-ASCII character '\xcf' in file”的问题。当我在正常模式下运行时还有另一个问题。 enter image description here SyntaxError: 非 ASCII 字符 '\xe6'

      要定义源代码编码,必须将魔术注释放在源文件中,作为文件的第一行或第二行(例如 /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/ pydev_monkey.py),例如: "# --coding:utf-8 --"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-18
        • 2017-03-01
        • 1970-01-01
        • 2011-06-03
        • 2014-12-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多