简体   繁体   English

文件中的非 ASCII 字符 '\\xe2' 但未声明编码

[英]Non-ASCII character '\xe2' in file but no encoding declared

I wrote a script to extract signals from the MIT-BIH dataset using the wfdb python library.我编写了一个脚本来使用wfdb python 库从 MIT-BIH 数据集中提取信号。 The script was working fine when I was running it on windows but I recently shifted to Mac .当我在windows上运行脚本时,它运行良好,但我最近转移到了Mac After installing all the dependencies I got an error when I tried to import processing from the wfdb library.安装所有依赖项后,当我尝试从wfdb库导入处理时出现错误。 This is the error I get:这是我得到的错误:

SyntaxError: Non-ASCII character '\\xe2' in file /usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py on line 3346, but no encoding declared;语法错误:第 3346 行文件 /usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py 中的非 ASCII 字符 '\\xe2',但未声明编码; see http://python.org/dev/peps/pep-0263/ for details有关详细信息,请参阅http://python.org/dev/peps/pep-0263/

import wfdb works fine but there seems to be a problem when I do from wfdb import processing . import wfdb 工作正常,但是当我执行from wfdb import processing时似乎有问题。 Is there any way to solve this issue?有没有办法解决这个问题?

Please add following line at the top of the code.请在代码顶部添加以下行。

# -*- coding: utf-8 -*-

Also, avoid using non-ascii quotations.另外,避免使用非 ascii 引用。

This error is caused due to copying and pasting code from web which causes stray byte floating.此错误是由于从 Web 复制和粘贴代码导致杂散字节浮动引起的。 You can find it by running.你可以通过运行找到它。

with open('my_script.py', 'r') as ms:
    for i, line in enumerate(ms):
        if '\xe2' in line:
            print(i, repr(line))

And the line and its index value will be printed where there is '\\xe2':并且该行及其索引值将打印在有 '\\xe2' 的地方:

4, "\xe2        word=string.printable(random.randint[0,61]) # Gets the random word"

Note: You should replace my_script.py with your respective .py file.注意:您应该将 my_script.py 替换为您各自的 .py 文件。

这是由于已修复的 scipy错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM