VS Code syntax highlighting Python f-strings - python

I've been using VS Code for Python for a while now, but after all this time I still haven't figured out how to syntax highlight my f-strings. I've seen screenshots of other people who have them highlighted properly, but mine look like this:
Is this something I have to manually change in my color scheme?

Can it output the correct result? In other words, f-string can work?
Have you tried to switch the color theme?
And can you open the Command Palette to execute the command of Developer: Inspect Editor Tokens and Scopes to get this:
Can you find the meta.fstring.python like the above picture?
This could be provided by the Built-in extension of Python Language Basic or MagicPython extension and so on. So could you disable all the python related extensions then only enable the Python and Built-in extension of Python Language Basic to make a try?

You can try changing the theme of VSCode. I usually use the Github theme and I can see proper syntax highlight. Also, make sure all the necessary extensions for python are installed.
Screenshot from VS Code

Related

How can I get Jupyter-notebook syntax highlighting in VS code?

I installed Visual Studio Code, and want to customize syntax highlight to be the same as Jupyter notebook. I'm using default light theme and that's good but colors of python built-in functions and methods aren't.
What should I do?
Since the code itself is written in python, as long as you have the language support you should get the Syntax Highlighting, Autocomplete and IntelliSense. See: https://code.visualstudio.com/docs/languages/python.
For a full walkthrough on setting up a jupyter-notebook see: https://code.visualstudio.com/docs/datascience/jupyter-notebooks
Seems there is a theme for that on the VS Code extensions site. You should be able to install it from the extensions tab on VS Code itself or through "Install" from that link.
Hope this helps.

Python note book autocomplete not working in VSCode with environment being CVE

I have done some research, but none of the solutions work for me and it seems that my situation is much worse than everybody else. Currently, my VSCode editor is just acting like a plain text editor for any ipynb files. For example, this is how my import block looks like:
Nothing has been highlighted, and I'm working with this for quite a long time and now I can't bear with this anymore. If this is not bad enough, then take a look at the following:
Literally, nothing happens. I think now the only help I get from VSCode is plain text auto-completion, but that is far from what anyone should have.
The configuration is pretty simple. I have the following kernels I can choose from:
And I'm mainly using anaconda3 for my kernel. Further, I only have
in my setting.json for python configuration.
As for extension, I have the standard python extension with python extension pack installed, which are the only two extensions I installed for python.
I'm really tired of working with plain text python code, if any information is needed, I can provide as much as I can.
-- Edit
It seems that the default language is not python, but CVE. Futhermore, I can't find the proper language to choose. All the language options are listed below.
The error happened because of the extension Dependency Analytics. Please uninstall it and reload window.
Reference: jupyter conflict with Dependency Analytics.
Click here and select Python.
CVE seems to be the default language for notebooks for some reason. Please check the settings.

Python auto import extension for VSCode

Is there a Python auto import extension/plugin available for Visual Studio Code?
By auto import I mean, auto import of python modules. Eclipse and Intellij has this feature with Java.
VSCode team recently released Pylance
Features
Docstrings
Signature help, with type information
Parameter suggestions
Code completion
Auto-imports (as well as add and remove import code actions)
As-you-type reporting of code errors and warnings (diagnostics)
Code outline
Code navigation
Code lens (references/implementations)
Type checking mode
Native multi-root workspace support
IntelliCode compatibility
Jupyter Notebooks compatibility
No, but it will soon be a part of vscode-python: https://github.com/Microsoft/vscode-python/pull/636
EDIT: See answer by #Eric, who built such an extension.
EDIT 2: See answer by #Eyal Levin, mentioning such an extension (Pylance).
I have built an automatic import extension that supports Python. It lets you fully customize how the imports get written to the file, modifying import paths, names, sorting relative to other imports. The Python plugin even lets you "group" imports together with extra line breaks.
From https://github.com/microsoft/python-language-server/issues/19#issuecomment-587303061:
For those who wonder how to trigger auto-importing as I did, here are
the steps.
Enable Microsoft Python Language Server by removing the check of
Python: Jedi Enabled in your settings.
Reload the VSCode window.
Hover your mouse over the variable that you want to import, and click Quick
fix...
For the last step, if it shows No quick fixes available or
Checking for quick fixes, you may need to wait for a while until the
extension has finished code analysis. It is also possible to set a
shortcut that triggers a quick fix.
I use this package it works very well
https://marketplace.visualstudio.com/items?itemName=codeavecjonathan.importmagic
You can find it in VSCode extension store. it's name is IMPORTMAGIC. It works fantastic. It will include all modules which you use in your script.
It has code action ctrl + . , which will also import library.
This is supported in the official Microsoft python extension, but for some reason I found it was recently disabled or no longer default. The setting I had to toggle was
"python.analysis.autoImportCompletions": true,
(Updated answer as of January 2023)
These three together did it for me:
"python.analysis.autoImportCompletions": true,
"python.analysis.autoImportUserSymbols": true,
"python.analysis.indexing": true,
If that is slowing down your computer too much because it's indexing too many files, then look into specifying patterns and depths of directories to include in the indexing using "python.analysis.packageIndexDepths".
Note that I am using Pylance (currently the default, as of January 2023).
Check out the VSCode python settings reference for more info on each of those settings.
You might find This Python-Based Module useful if you wish to auto import and auto download missing modules from a script or sub-scripts. Not only for VSCode, but also for any IDE or Editor.

How to get syntax highlighting for .enaml files in PyCharm?

I am trying to learn Enaml, which is an extension to the Python language that allows you to define hierarchical trees of objects used for graphical user interfaces.
Since enaml is a super-set of the Python language, its syntax can be different from Python's one and IDEs do not highlight it.
Is there any way to get enaml-syntax highlighting in PyCharm? Or maybe in some other IDE?
(I know that the package 'enaml-pygments' exists, but I have no idea how to make it work for automatic enaml-syntax highlighting in an IDE.)
I've added most of the keywords to this repo which you can import into PyCharm:
There are highlighters for a few editors in the Enaml repo. Maybe one of them can be used by PyCharm: https://github.com/nucleic/enaml/tree/master/tools
Today I found this settings menu that partially addresses the issue of adding any syntax to PyCharm:
https://blog.jetbrains.com/idea/2010/09/custom-file-types-in-intellij-idea/
Unfortunately it captures only the most simple features of a syntax.
I'm using Atom to work with Python/Enaml code. With the language-enaml package you get syntax highlighting plus some autoextension and docstring feature for Enaml (https://atom.io/packages/language-enaml). Add in git integration and packages like build-python to run you code from the editor and you have quite a nice IDE.
https://github.com/vahndi/pycharm-enaml-keywords
Open PyCharm
Go to File,
Import Settings...,
browse to the .jar file and click OK
Select All,
OK

Sublime3 text can't ignore PEP8 formatting for Python

I installed Sublime for Python programming but I found that PEP8 error detection is pretty annoying and I couldn't get rid of it.
I tried this but it's not working:
It kept showing this:
Try to add "pep8": false,.
If it does not work, add "sublimelinter_disable":["python"], to disable python's inspections completely.
And you would like to look https://github.com/SublimeLinter/SublimeLinter-pep8

Categories