How to solve unexpected token parser 16 visual studio code - python

When I am writing Python in V.S. Code, I keep getting errors that highlight a good portion of my code base. IntelliCode shows an error message that reads:
"unexpected token '=' Python(parser-16)"
So, it appear to stem specifically from specific lines, and when the lines are copy & pasted they inherit the errors, however; if you type-out the line anew, the error is resolved? It is a perplexing issue.

There are 3 things that could be
The first is simple, restart your editor and see if the issue persists.
The second thing it could be is an old unmaintained extension:
Installing the wrong extensions can cause headaches and hard-to-solve issues. This is why installing extensions because it's fun, and they are free, is a bad idea. You should always have a decent reason for installing an extension, and should always avoid installing an extension under the pretense that you may, one day, need it.
When it comes to an opensource editor like VSCode, extensions are Hit & miss, which is, to say the least. Sometimes you might find a hidden-gem, or something new the surprises you unexpectedly in a good way, but you need to have a reason to be looking for a specific extension because you need to know what your look for, many extensions offer features that VSCode now supports out of the box, some extensions haven't been upgraded for 2-3 years, and are full of deprecated code. There is an example of a repository that was maintained by Microsoft up until 2020. People are still creating issues that reference parser 16 errors, and they only get a response that the repository is no longer maintained, and a suggestion to use a different tool."_
Here's the link to the repository I mentioned above. I don't know what extensions you are using, but if it uses this old language server repo, which is for some reason still active, you will want to swap out that extension for something else, or just toss it all together.
To test if it is an extension perform the simple steps below:
To confirm that it is an extension...
OPEN Your Project inside of V.S. Code
HIT F1 to open up your quick input menu
TYPE: "Reload window with extensions disabled"
SELECT the command from the menu that matches the text you typed in step-3 above ("Reload Window with Extensions Disabled") (or workbench.action.reloadWindowWithExtensionsDisabled)
After the editor reloads check your and see if the issue persists.
The problem should go away, as you shouldn't have syntax highlighting from an extension enabled. You need to accomplish having Syntax Highlighting W/O having the issue though. To do this you're going to temporarily leave all of your extensions disabled, then, if you don't have it, install the extension pack that is called:
Python (that's it, its just called "Python").
If you do have it, then just enable it. The V.S. Code Python Extension adds Microsoft support to V.S. Code for Python. Make sure that the extension ID-Name is ms-python. python, that it was developed by Microsoft, and that you have the latest version.
After you have your project open with all extensions, except for the Microsoft Python extension installed, see if the issue is gone and that your syntax highlighting works.
The third and last thing it could be is the Python Extensions parser is unable to parse your code, which may, or may not be your fault.
If the above did not solve your issue then it's likely that the issue is a problem with your code, which may, or may not, be your fault. Python syntax is funny, as it's far different than other c-style languages, yet it is still very much C-style. In the past, I have seen parser 16 errors caused by F-strings, and R-Strings, because of bugs in the parser. They either had a hard time picking up multiple quotes """ in a row, or they had a hard time, picking up a logic-operator with multiple quotes, the syntax written like the following example would cause an error in specific use cases:
"""!==
You need to go through, make sure it's not a mistake on your end, you can even post your code here, which would help the community to determine if its a bug, especially if you can confirm for us that you have only the python extension active while you are getting the error.
If you determine that your codebase is in working order, and if you are right, it is in working order, then it is likely a bug, but you need to like really, really be sure. Once you are sure, go to the following repository and create an issue.
VSCode-Python Repository (CLICK HERE)

Some characters might not be what they look like on text editor.
For example:
Non-breaking space is different from space even though they look the same.
״ is different from " even though the looks similar on the screen.
’ different from ' even though the looks similar on the screen.
So when copy a code and paste a code from somewhere and you get syntax errors you do not understand such as unexpected token, Try to replace the characters at the relevant locations.

Had similar problem with python code.
In my case restarting VSC solved problem.

Debugging the problem
Turn off extensions
To test if one of your VSCode extensions is causing the error, open the command pallatte(cmd+shift+p or ctrl+shift+p) and select Reload Window with Extensions Disabled to see if the problem still exists without any extensions
Start Extension Bisect
Also, if you go to the vscode extensions marketplace, there is an option called start extension bisect which vscode explains as
Extension Bisect will use binary search to find an extension that causes a problem. During the process the window reloads repeatedly (~7 times). Each time you must confirm if you are still seeing problems.
Advice on Extensions
The Python extension that is developed by microsoft is ms-python.python, this is usually the one you want
Don't install extensions you don't understand, it can cause hard-to-solve problems.
Any time you do install an extension, check to see if you are having any errors or problems.

Related

What package is causing Atom to reformat my Python files on-save?

Every time I save a Python file on my Atom text editor, it gets automatically reformatted.
Usually this is a good thing, but sometimes it's extremely frustrating, in certain situations where the formatter makes bad choices.
What package is causing this behavior and how can I disable it?
I have confirmed that atom-ide-ui was indeed the culprit. Note that the repo for that project is now archived.

PyInstaller ImportError DLL not found when testing EXE on other computer

I built an EXE file from a Python script using PyInstaller, using
pyinstaller --onefile myscript.py
Packages I used:
pandas, numpy, imutils, opencv, logging, os, random, json, string, csv, datetime, uuid
The EXE runs fine on my PC. However, when I try it on another PC I get the error shown in this screenshot: https://www.screencast.com/t/msZrURL4v
Any idea what the problem is?
The error you post just says "I was looking for one specific DLL and did not find it".
Rather than installing other packages and extensions that might, or might not, be or somehow contain the right DLL, you now need to determine exactly what it is that isn't to be found.
I can suggest three complementary methods, none absolutely certain to pinpoint the exact problem (of course the voodoo method of "install some package at random and see whether it fixes it" might also work, and often does -- but that's magic, not computer science):
the quickest: check the pyimod03_importers.py file at line 714, see what it was doing when the exception was thrown. Due to Windows' library loading strategies, you might be handed a red herring, with a file reported not to be there when it actually is, because it relies on a second missing file whose name you won't be told.
the easiest: use a tool like SysInternals' DEPENDS.EXE to inspect the OMR.EXE file. This is almost guaranteed not to work in this case, because the needed imports might be specified in Python format, not in any form that DEPENDS.EXE will recognize.
the most comprehensive, but least easy: use a tool like SysInternals' PROCMON, set up the filters to exclude the background noise of Windows' idle state - there will be an awful lot of that - and then fake running OMR.EXE; exclude the additional noise generated by that. You'll need about fortyish filters to be set up. Finally run OMR.EXE. Near the end, you will see a series of attempt to load SOMETHING.DLL, all failed; the first is where the DLL is supposed to be (by either Python or OMR), the others are all suitable alternatives.
Then:
if the DLL is one of yours, find out how to pack them with the EXE bundle.
if it is not, you need to reliably assess where it can be found.
It might well be that the suggestion you were given - install MSVC redistributable that-version-or-other - was absolutely correct. Libraries with names like MSVCnn... belong to that package. MSO... files usually belong to Microsoft Office redistributables. MSJET... files are found in several Microsoft package, for example the .NET redistributable.
otherwise, Google and possibly MSDN Search Engine are your friends.
From past experience, I suggest setting up a virtual machine for testing, then seeing what packages are needed. This is because the first DLL crash will hide any subsequent ones, and you might need to repeat the above steps several times. The fact that the first library you need is supplied by the NETFX64 package and the second by the Microsoft Office runtime might be true, but when you find out that the second library is needed, you might also find out that the MSO runtime would have supplied the first also; so at that point, and not before, you discover that the NETFX64 package wasn't really needed, and can simplify your installation requirements to the MSO runtime alone.
Boiling down the requirements to a short list might be a lengthy task and you will want to restart the machine from scratch more than once. With a VM, that is easy to do.
(I've kept referring to the MSO runtime because I figure that your program will process a checkbox answers module, and will likey need or believe it needs some scanner recognition features, which the MSO runtime supplies. If that is so, they'll probably come last).

PyCharm autocomplete for imported modules

I'm new to Python and trying to get comfortable with the syntax and the language. I gave PyCharm a shot and found it very comfortable.
The only problem is that auto-completion isn't working as I expected and it is very important to me as part of the learning process and looking into some modules.
My code works even without the autocomplete but I'm very used to it and really wish to enjoy this feature.
I tried changing my project interpreter back and forth and nothing changed. I tried restarting PyCharm, the computer - didn't work. I tried Invalidate Cache, made sure the power save mode is off - nada.
Here is an example of missing autocomplete for lxml:
And here is the interpreter window:
Python is a dynamically typed language, so the return type of a function is not always known in advance. PyCharm generally looks at the source of a function to guess what it returns. It can't in this case because etree.parse is written in Cython, not Python. If you ask PyCharm to go to the definition of the function it gives you a stub.
The Python ecosystem has recently started to tackle this problem by providing various ways to annotate files with type hints for use by external tools, including PyCharm. One way is through .pyi files. A large collection of these can be found in the typeshed project. This issue shows that writing hints for lxml was proving difficult, and not wanting to have incomplete stubs in the typeshed repo, they were moved to their own repo here. The stubs are indeed very incomplete, and when I tried downloading and using them in PyCharm the results were pretty dismal. They correctly identify that etree.parse returns an etree._ElementTree, but the stub for _ElementTree only has two methods.
I got much better results by annotating directly in the Python file, e.g.
tree = etree.parse(path) # type: etree._ElementTree
(you can find out the type by checking type(tree))
PyCharm itself somehow knows what the methods on _ElementTree are so now autocomplete works. Unfortunately it seems that using .pyi files makes PyCharm forget this knowledge.
Here is documentation on type hinting in PyCharm.
And yes, in general you will have to get used to less autocompletion and general type information and static analysis. Fortunately I think there is a lot to make up for it that isn't possible in other languages :)
Install KITE, its a super fast auto suggest engine for python. It works for Pycharm,Sublime etc...
For more details view this youtube video

Visual Studio 2017 not recognising errors in code

I just installed the Python development workload for VS 2017 but the editor shows none of the red squiggly underlining for syntax errors that I'm used to seeing with C# on VS, nor any entries in the error list. If I try to run the code with errors, it warns me there are errors in the code but does not specify what they until exceptions are thrown from running.
I've tried reinstalling the workload and looked through every available option under the Tools/Options tab but can find nothing about syntax errors. Any fixes detailed for earlier versions of VS no longer seem to apply, what am I missing?
I had exactly the same problem using the simplest project from the VS Python tutorial.
The fix was to upgrade from VS 15.4.1 to 15.5.
Walt
I have had the same thing happen to me. Though this was actually with a C# application. I noticed Visual Studios stopped detecting the errors after adding a few NuGet references and doing some manual modifications of the project files. I noticed that this was only happening on this one project. All the other projects I worked on did not seem to have the same issue.
I was able to get it to start working again by creating a new project, moving my code over, and adding the references back one by one. For this situation, it looked as if a corrupt project file or bad reference was to blame even though the project would compile and run correctly.
Does this issue exist in other programming languages/projects?

Python D-Bus on Windows with MiNGW

I'm following this tutorial to get my Python application (which use DBus) working on windows.
I'am at the step Build DBus (using MiNGW and therefore gcc).
So, here we are at my problem: There is an error while compiling:
As you can see, it's just a syntax problem...
I've tried to fix it directly into the concerned file, but lt-dbus-monitor.c seems to be a generated one and i've not been able to find which generates it (The makefile is so obfuscated).
May someone have a solution to this ?
All right, i feel a bit stupid...
For those who will be interested: I've just replaced spaces from "scratch MiNGW DBus" with underscores...
I guess it does not like spaces in folder name, obviously.

Categories

Resources