Why aren't my sublime-anaconda gutter marks showing up? - python

I was watching Corey Schafer's video on YouTube on 'Setting up a Python Developer Environment in sublime Text'.
I installed the anaconda package, but for some reason, the gutter marks (for linting) are not showing in the line number column.
I have not altered the default settings.
I have added Corey's user settings to the sublime-anaconda user settings file:
{
"auto_formatting": true,
"autoformat_ignore":
[
],
"pep8_ignore":
[
"E501"
],
"anaconda_linter_underlines": false,
"anaconda_gutter_marks": true,
"anaconda_linter_mark_style": "none",
"display_signatures": false,
"disable_anaconda_completion": true,
"python_interpreter": "/usr/local/bin/python3"
}
I should note that I have also tried adding:
"anaconda_gutter_marks": true,
to no avail.
I have also saved the settings and restarted sublime text.

You need to change your "python_interpreter" setting to the actual path of the python.exe executable on your system. Opening cmd and entering which python may be helpful in finding it. Once you've found it, change and \ characters to / - for example, C:\Python38\python.exe would become C:/Python38/python.exe.

Where you've copied the code from correy's GitHub there is a line called "python_interpreter": "/usr/local/bin/python3" just delete that line and restart sublime and the errors should be showing again.
Check the screenshot:

Related

How do i remove the unnecessary text in the terminal in vscode?

Hi i'm new into vscode and when i run a program there is some text that i want to get rid of.
i mainly want to remove the first two paragraphs, but also removing the path would be ideal
i tried code runner but thats not the solution i'm looking for
i also tried changing the color to black but i reckon there is a way to remove it
Adding the "-NoLogo" start parameter will remove the paragraph of text; If you open your settings file (Ctrl+Shift+P and then type "Settings" -> User Settings JSON), you can use the following bit of configuration:
// should go in the main JSON object with the other keys
"terminal.integrated.profiles.windows": {
// it might generate some more profiles automatically, but powershell is what matters
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-NoLogo"]
}
}
I believe by default those lines will always appear because those are the one that show up when you open cmd on Windows.
Also, by default, the path open to the current project folder, that the reason why you see the path.
You can do a cls to clear the terminal, but the path will remain unless you change the directory.
You can read more about VS Code integrated terminal here and about terminal profiles here
First go to terminal settings and then the add -nologo arg

VS Code ignores global `tabSize` setting

Relevant user settings:
"editor.tabSize": 2,
"editor.detectIndentation": false,
Workspace settings are empty. Using VS Code 1.52.0.
.cpp files get formatted properly (using the Format Document option), yet in .py files it changes all indents to 4 spaces and inserts some unnecessary vertical spacing (like, double empty lines in some places). The only settings specific to Python are pythonPath and condaPath.
Edit: Inserting this:
"python.formatting.autopep8Args": [
"--ignore",
"E301, E302, E305, E306, E101, E11"
],
into settings.json stops it from changing 2 space indents into 4 space indents, but now it just ignores indentation altogether. I want it to correct indentation to 2 spaces. Used this for reference.
Edit: I want this:
to be fixed to this:
but it gets fixed like this instead:
Please use the following settings in "settings.json":
"python.formatting.autopep8Args": ["--indent-size=2"],
Related settings I use:
"editor.tabSize": 2,
"editor.detectIndentation": false,
"editor.renderWhitespace": "all",
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": ["--indent-size=2"],

Visual Studio Code and Jinja templates

I use VS code since a while with some Extensions.
All is perfect expect when I use Flask.
Prettier put all flask code glued together, and intellisence is not working with flask code:
{% extends "layout.html" %} {% block style %} body {color: red; } {% endblock %}
{% block body %} you must provide a name {% endblock %}
What can I do to make it work with flask (trie flask-snippets)?
I run it in virtuel env (run before lauch vscode).
Thanks in advance,
I also had a similar problem and this is what I did to fix it :
Install the Better Jinja plugin. (https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml)
This will allow you to change the file association from plain "HTML" to "jinja-html" (it's on the lower right part of my vscode screen), and this will stop jinja codes from sticking to one another on save.
At this stage your intellisense will not work anymore, causing a lot of annoyance, so :
Go to preferences >> settings >> type "file associations" in the search settings bar, click on "edit settings.json"
Finally add the following line to the settings.json file :
"emmet.includeLanguages": {"jinja-html": "html"},
Restart your vscode. Every time you open an html file with jinja templating codes, as long as jinja-html is selected (not HTML!), prettify won't mess it up, and your intellisense should be working just fine. :)
add this like the screenshot below
"files.associations": {
"*.html": "jinja-html"
},
[screenshot]
Ok, so I tried the solutions from Ataua and Moby J, but wasn't able to get them to work. Maybe because I'm using Prettier globally.
Here's what worked for me:
There's a project called Unibeautify that seems kind of like a "one ring to rule them all" for tying together personalized settings across different formatters and filetypes.
It has a VS Code extension, VSCode-Unibeautify.
After installing the extension, you need to create a config file and tell VS Code where to find it. You can create and customize your own config if you want to use it for multiple languages, but here's what worked for me for Jinja:
# unibeautifyrc.yaml
HTML:
beautifiers:
- JS-Beautify
- Pretty Diff
and then, in your vscode settings:
// settings.json
"unibeautify.defaultConfig": "/PATH/TO/unibeautifyrc.yaml",
"unibeautify.enabled": true,
"[jinja-html]": {
"editor.defaultFormatter": "Glavin001.unibeautify-vscode",
"editor.formatOnSave": true
},
What I've done also, is to associate html files with the Jinja filetype in my project's settings.json. This helps if you just want to limit the use of Unibeautify to just Jinja files on a project by project basis. I think you could also make the below *.html more specific to your templates directory if you prefer.
// MYPROJECT/.vscode/settings.json
{
"files.associations": {
"*.html": "jinja-html"
}
}
This solution is powered by JS-Beautify which seems to work well with Jinja and powers Atoms atom-beautify extension, also by the same author of Unibeautify, Glavin001, a beautiful individual.
I have tried everything but at last, it worked for me.
Install the Better Jinja plugin.
Install the django plugin
Then go to settings by pressing ctrl+,, and search for file associations and goto settings.json and edit the following:
"files.associations": { "*.html": "jinja-html" },
"emmet.includeLanguages": {"jinja-html": "html"},
The aforementioned solutions did not quite work for me. I either lost highlighting, autocompletion or autoformatting.
I finally found a solution that gave me all of that:
Install "Better Jinja" or "Django" (better syntax highlighting within double quotes) plugin
Install "djLint" plugin
Press CTRL + Shift + P and type open settings json + Enter
This is my config and it works great for my jinja templates. djLint has more filetype-specific options to offer (see extension-description in VS Code).
// settings.json
"emmet.includeLanguages": {
"jinja2": "html",
"jinja-html": "html",
"django-html": "html",
},
"[jinja]": {
"editor.defaultFormatter": "monosans.djlint",
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
},
"[jinja-html]": {
"editor.defaultFormatter": "monosans.djlint",
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnSave": true,
},
"[django-html]": {
"editor.defaultFormatter": "monosans.djlint",
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.formatOnPaste": true,
},
My jinja-templates use the extension .jinja2. To make it work with the "Django" plugin I add this to my settings:
// settings.json
"files.associations": {
"*.jinja2": "django-html"
},
The only complaint I have now is that I can't get the linked editing of tags to work :-D
The answer from Mobi J helped me but I think it was icomplete.
What did solve the same issue I was having was to add those two lines at the very ending of settings.json (before the last closing bracket):
"emmet.includeLanguages": { "jinja-html": "html" },
"editor.defaultFormatter": "vscode.emmet"
I actually did so by navigating Settings (Ctrl + , on Linux), but the result is just that addition to the settings.json file.
After that change, both intellisense and emmet are working, in .html and in .jinja files.

Visual Studio code with PyLint and autoPep8: How can I avoid PyLint to complain about my line length?

I recently switched to Visual Studio Code and I have to say I love it so far.
I'm working on a Python project, which includes the pip packages pylint and autopep8 and I configured VSCode to format the code according to these packages.
Only problem is: In the Python project I'm working on the line length is 100. So all my code looks like this:
The error says: E501:line too long (97 > 79 characters). Here are my VSCode settings:
{
"python.pythonPath": "~/.envs/myProject/bin/python",
"python.linting.pep8Enabled": true,
"python.linting.pylintPath": "~/.envs/myProject/bin/pylint",
"python.linting.pylintArgs": ["--load-plugins", "pylint_django", "--max-line-length=100"],
"python.formatting.autopep8Args": ["--max-line-length=100"],
"python.linting.pylintEnabled": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
".vscode": true,
"**/*.pyc": true
}
}
These settings at least now ensure that format on save keeps the lines at 100 max and does not wrap all my files lines to 79. Still it would be awesome without the warnings.
How do I disable these linter warnings?
I figured out how to do this. Add this line to your settings:
"python.linting.pep8Args": ["--max-line-length=100"],
For pycodestyle in Vscode 1.15.1:
"python.linting.pycodestyleArgs": ["--max-line-length=100"],
As of 2021 (Pylint reference), add this to your .vscode/settings.json file:
"python.linting.pylintArgs": ["--max-line-length=100"]
2020 version:
Add the following entry to your settings.json file
"python.linting.pylintArgs": ["-d", "C0301"],
If you haven't disabled these errors, and encounter a line too long warning, under "Problems" in VSCode, or by hovering over the underlined error, you will see VSCode say something along the lines of:
Line too long (188/100)Pylint(C0301:line-too-long)
As you can see, the value C0301 comes directly from this warning message. You can additionally disable other warnings by their error code as well.
For me the following worked. (VSCode version == 1.73.0)
Go to Settings.
Search "pylint".
Scroll down to "Pylint : Args"
Click "Add Item"
Type this in, --max-line-length=200
Adjust the max-line-length to your desired length.

jupyter notebook python version 2.7.13 (print invalid syntax error)

Hi I have a Jupyter Notebook, with python 2.7.13 and it worked fine all along. But starting today it shows strange behaviour.
when I do this in a fresh notebook Python 2:
print 'hello'
it returns this:
File "<ipython-input-1-bfbe230352b8>", line 1
print 'hello'
^
SyntaxError: invalid syntax
It was working ok till yesterday and today I restarted the computer and this happens.
Any reasons? How to fix?
I have checked anaconda, spyder, command prompt... everywhere else is ok with 2.7.13
print ('hello') works but I don't want this.. all my code is in Python 2.
I have now tracked the problem to be caused by the extension. Once I rename this file C:\Users\X\.jupyter\nbconfig\notebook.json to something else and reopen jupyter notebook, the print works as expected.
However, I do need the extensions at least the key ones I use regularly. I don't know which one to disable. I didn't know how to track the culprit without going through each one by one. Also, as far as I can remember, all the extensions I have been using for few weeks already without any issues.
These are the contents of the notebook.json file.
{
"load_extensions": {
"toc2/main": true,
"Runtools": true,
"collapsible_headings/main": true,
"codefolding/main": true,
"varInspector/main": true,
"runtools/main": true,
"runtools": true
},
"collapsible_headings": {
"add_button": true,
"add_insert_header_buttons": true
}
}
After trial and error with disabling one every time, restart and check.. I have now solved the problem by setting this line to false, it now works. The problem is with variable inspector extension.
"varInspector/main": false,
Sometimes the jupyter required a restart and sometime it didn't. Just opening the .ipynb file was enough to test.
I have the same extension running in my office computer, which has no issues.
If someone could really put in the comments for the cause and a solution for permanent fix of this problem will be great.
Could you please try with reloading sys like below ?
import sys
reload(sys)
print 'hello'

Categories