Spyder: Problem decoding source (pyflakes E) (Spyder 4)

Created on 21 Dec 2019  路  27Comments  路  Source: spyder-ide/spyder

Image below; occurred seemingly randomly when editing code in a separate Spyder window (via "new window"); no clue how to reproduce. As is seen, commenting out the offending line doesn't help; what does: (1) commenting out entire file code; (2) causing syntax error elsewhere in code (but as soon as either is undone, error returns).

Also, when I un-commented that first line, Spyder froze and I had to restart it (after which the error's gone). I like the new features, but hope these are fixed soon as they're rather disruptive.


image

Code Completion Bug

Most helpful comment

@ccordoba12 I think even add # -*- coding: utf-8 -*- doesn't help. I had the same issue. When I create a new file, the error icon occurs exactly like above. @OverLordGoldDragon The way I solve this problem is to close the file and reopen the same script. Then the icon is gone.

All 27 comments

Image below; occurred seemingly randomly when editing code in a separate Spyder window; no clue how to reproduce

You need to provide us with a reproducible use case. Otherwise, we'll be unable to solve this.

I like the new features, but hope these are fixed soon as they're rather disruptive.

I understand your frustration, but this kind of error reports are also frustrating for us because it's more like a complaint than a proper bug report.

this kind of error reports are also frustrating for us because it's more like a complaint than a proper bug report.

Agreed, but again they appear to simply come and go - it's rather a lose-lose situation. If I manage to find reproducible steps, will update.

@OverLordGoldDragon What you have shown are imports without how they are used or where they came from. Can you reproduce the symptoms that you described in a smaller program with fewer external import dependencies? A source file that can be compiled by Python 3 or analyzed by pylint by other people would facilitate investigation.

@OverLordGoldDragon, I was also thinking about this yesterday, and it could be related to using an encoding different than utf-8 in the files you opened in Spyder's editor.

Is that the case with the file you shown above?

@ccordoba12 I haven't pasted anything into the .py files, which I typed from scratch, and haven't tweaked encoding options. Regardless, how would I view what encoding a .py file uses?

@texadactyl model_utils imports from keras or tensorflow.keras depending on the os.environ["TF_KERAS"] flag - I'll see if I can narrow it down next time it occurs

I haven't pasted anything into the .py files, which I typed from scratch

Did you write them entirely in Spyder?

Regardless, how would I view what encoding a .py file uses?

It's shown in the status bar:

Selecci贸n_069

In this case, the file has the UTF-8 encoding.

Did you write them entirely in Spyder?

Cannot guarantee I never pasted a single character from elsewhere, no - but vast majority is indeed typed in Spyder

And... bingo, you may be onto something:

image

I haven't had this specific problem recur ever since, but in case encoding is important for some other bugs or general stability - how do I swap to UTF-8?

You need to add this comment

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

to the top of your files (i.e. it needs to be the first line in them).

@ccordoba12 I think even add # -*- coding: utf-8 -*- doesn't help. I had the same issue. When I create a new file, the error icon occurs exactly like above. @OverLordGoldDragon The way I solve this problem is to close the file and reopen the same script. Then the icon is gone.

I do not think we are changing the encoding on the fly with just adding that line, that is why the reopen is necessary. Other IDEs provide the option to change the encoding with a menu entry. We could also provide thus by making the status bar item clickable (which would display enconding options with a menu/dropdown)

Had this problem today. Restarting spyder fixed it.

To notify, I've never had this problem since - though I've been using # -*- coding: utf-8 -*- atop each file.

@OverLordGoldDragon, could you please provide us with a minimum reproducible file that presents this issue?

@andfoy Unsure, the behavior is spontaneous - I was just editing a file and it popped up. There is no file that has this marking upon simply opening it. Maybe there's a 'trigger' though - it happened after linter marked a Syntax error which I resolved; I'll notify if I find anything.

I just faced the same issue, googled it, and ended up in here. Since I could not find a solution here, I thought to close and reopen the file, and that solved the problem. Also, while I faced this error, all other errors in the script were ignored by the IDE, but warnings, such as docstring missing, were shown.
I write all my scripts in Spyder, and always use default settings, encoding UTF-8, etc. And this was the first time I bumped into this error. Interestingly enough, this was the first time in Spyder 4 I was writing a class in a separate file. Not sure if it is significant, but at least we now know one easy solution to get rid of the error.

I have the same issue 1-2 times per week since creating a new environment with spyder 4. I don't recall seeing it in the half year I've worked with spyder 3. All my files start with _# -- coding: utf-8 --_ and I've changed only the appearance (to pydev). Pyflakes locks up, red cross stays where it is, also if the line is now empty. Restarting Spyder to resolve works. I also run keras. I have not yet observed a way to trigger it, so I won't be able to create a use case.

@OverLordGoldDragon, have you seen this after PR #12771?

@ccordoba12 No, but I've seen it only once since 4.12 or 4.11 anyway, so doubt my install is a useful reference. If 4.14 isn't coming soon, perhaps we could suggest users to try the PR fix.

Agreed. @frankcoumans, please check PR #12771 for a possible fix for this.

Thank you! Applied the fix. Will let you know if I see it again.

@ccordoba12 I havent't seen pyflakes lock up since applying PR #12771 about a week ago.

Thanks again!

@frankcoumans, thanks for the confirmation! Let's close this one then.

@ccordoba12 It popped up again, and I still have #12771 applied. Reopening the file made the message disappear.

Also, I don't think the "auto UTF-8" is working (assuming it's part of 4.1.3); it defaults to ASCII if not using # -*- coding: utf-8 -*-.

Please open a new issue about that and try to give us a reproducible case or video for us to reproduce it.

I also occasionally have the issue, but Pyflakes doesn't stay locked on an error anymore; the red x now disappears when the offending line is removed. However, Pyflakes just stops checking the code for a while and then resumes operation (without reopening the file, but after running the code in debug mode). It's not really been a problem, and it's so rare that I have no clue how to reproduce.

@ccordoba12 If I can reproduce, sure, but similar to @frankcoumans, this is very rare and minimally problematic as resolution is trivial.

Ok, that's really good to know! Please keep us posted after 4.1.4 is released to see if things stay like that or regress to the previous behavior.

Was this page helpful?
5 / 5 - 1 ratings