Visual Studio Code is not recogonizing an Autopep8 installation - visual-studio-code

I use Visual Studio Code for developing in Django. I did all of the following inside a virtual environment.
Whenever I save the Python (.py) files, an alert pops up at the bottom right of the screen telling me: "Formatter autopep8 is not installed. Install?". It gives me three options - "Yes", "Use black, and "Use yapf".
If I click "Yes", it gives me another alert saying that there is no pip installer available in the selected environment. I then tried to go inside the integrated terminal and run pip install autopep8 and it says in the terminal that it was installed successfully. But when I save the Python files, it still gives me the same alert. Check the photo below.

Open your command palette with Shift + ⌘ + P. Type in Preferences: Open Workspace Settings. I'll share the settings I use with you, some of which may be of interest:
{
"python.pythonPath": "${workspaceFolder}/backend/env/bin/python3",
"python.venvPath": "${workspaceFolder}/backend/env",
"python.linting.flake8Enabled": true,
"python.linting.flake8Path": "flake8",
"python.linting.flake8Args": ["--ignore", "E501"],
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "pylint",
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
}
python.pythonPath is the location of the Python interpreter executable within your virtual environment. In this case it's an environment named env in a folder named backend. *${workspaceFolder} is a reference to where your project lives.
python.venvPath is the folder of your virtual environment(s).
The remaining six key/values are for enabling and execution for flake8 and pylint. Experiment with either.
Note that these are the workspace settings and not the user settings. User settings are applied across all of your Visual Studio Code projects.

Related

Stop automatic `conda activate` when opening a terminal in VS Code

VS Code has started running conda activate every time I open a terminal in VSCode, be it PowerShell, WSL, or CMD.
I never set this up intentionally so have no idea why it does this or how to disable it. I've looked at all my settings in VS Code and cannot find anything.
How do I stop VS Code from running conda activate when a new terminal is opened?
Try putting the following in your settings.json file:
"python.terminal.activateEnvironment": false
You're getting this behaviour because the default value of that setting is true if not specified.
For more info, see VS Code's docs on Using Python environments in VS Code- in particular, the Working with Python interpreters
section, and the Environments and Terminal windows
section.
Quoting from that page:
Tip: To prevent automatic activation of a selected environment, add "python.terminal.activateEnvironment": false to your settings.json file (it can be placed anywhere as a sibling to the existing settings).
Reading the changelog, this setting was added in version 2018.9.0 of the Python extension for VS Code. The PR that added it was #1387.

VS Code- "Run" button not appearing for my Jupyter Notebook, even after installing extensions and setting kernel

TL;DR: how can I run my Jupyter notbook in VS Code, given I've tried the previously-suggested solutions (like installing certain extensions) and nothing appears to be working?
I've got the following blank .ipynb file:
I've installed both Microsoft's Jupyter and Python extensions installed:
I created the file in screenshot #1 above via the command palette to Jupyter > Create New Blank Notebook. We see a cell which I've changed from plain text to Python. I don't see a "Run" button in my editor like I do in the VS Code + Jupyter docs. I hit Shift-Enter to run the cell, but instead of the expected output, I'm prompted to "Select a kernel for Untitled-1.ipynb`:
I try to type in my best guess for which kernel they're referring to (I use Python 3.9.5 in my terminal), but typing things like 3.9.5 and Python, thinking I might see an auto-complete helper or a dropdown with valid options to choose from, but this didn't happen.
The "Restart" and "Interrupt" buttons are greyed-out and disabled, implying that the Jupyter server isn't running. However, the docs imply that I should be able to just create a new Jupyter notebook and start running code immediately:
Here’s how to get started with Jupyter in VS Code.
If you don’t already have an existing Jupyter Notebook file, open the
VS Code Command Palette with the shortcut CTRL + SHIFT + P (Windows)
or Command + SHIFT + P (macOS), and run the “Python: Create Blank New
Jupyter Notebook” command.
If you already have a Jupyter Notebook
file, it’s as simple as just opening that file in VS Code. It will
automatically open with the new native Jupyter editor.
Once you have a Jupyter Notebook open, you can add new cells, write code in cells, run cells, and perform other notebook actions.
I saw the following Jupyter Server: local component at the bottom of my screen. I see the icon on the left-hand side shows a disconnected power cord; not sure if that implies the server itself is disconnected. At any rate, I tried clicking on this component to see what would happen:
I see the default behavior is already selected, which leads me to believe that VS Code would automatically start up a Jupyter server when the app itself is launched.
I also tried setting the kernel via the command palette (Jupyter > Select interpreter to start Jupyter server), and this time I did see my version of Python. However, selecting that option didn't seem to resolve the issue, since I still don't see a "Run" button:
I tried looking in all the tabs at the bottom of the screen (Terminal, Jupyter Variables, Debug Console, Problems, and Output), but didn't see anything at all.
Interestingly, when I run Jupyter > Create Interactive Window from the command palette, I am able to create Jupyter cells and run Python code in them. However, I consider this to be a workaround and not a solution to my primary problem of being unable to run both interactive sessions and notebooks:
These are all my VS Code settings:
{
"ruby.intellisense": "rubyLocate",
"files.autoSave": "onFocusChange",
"workbench.editor.showTabs": true,
"diffEditor.ignoreTrimWhitespace": false,
"files.trimTrailingWhitespace": true,
"editor.tabSize": 2,
"editor.tabCompletion": "on",
"workbench.colorCustomizations": {
"editorUnnecessaryCode.border": "#dd7aab"
},
"window.zoomLevel": 1,
"terminal.integrated.shell.osx": "/bin/zsh",
"[yaml]": {
"breadcrumbs.showEvents": true,
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": "advanced"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.editor.untitled.hint": "hidden",
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook"
},
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"python.defaultInterpreterPath": "/usr/local/bin/python3",
"notebook.lineNumbers": "on",
"jupyter.variableQueries": [
],
}
What am I missing?
Here is your answer,
1.Just refresh your IDE and then restart your IDE .
2.INSTALL KERNEL ON YOUR IDE.
Sometimes extensions in IDE must not have hosted therefore the extensions does not work.In this case just restart your IDE and then host your extensions.
I am not sure if you're still searching for an answer.
What worked for me was to install conda (anaconda or miniconda will do).
Then in the command prompt, type:
conda install ipykernel
Restart your IDE and it should work!
I had this issue too and solved it by:
pip install ipython
After installing this package and Jupyter extensions in Visual Studio code, the run button is available left of the cell and you can click it to run the cell.
Then it tries to connect to the kernel and for the first time asks you to install Ipykernel if it doesn't show this message, etc you can run this code in Command Prompt:
python -m pip install ipykernel
also for more information, you can see this page:
https://ipython.readthedocs.io/en/latest/install/index.html
Go to Extension
Search "Jupyter" from Microsoft
Click "Switch to Pre-Release Version"
Click "Reload"
VS Code Extension

How do I get around the verified bug in Windows 1903 and launch the VSCode integrated terminal?

I just did a fresh install of Windows 10 Pro version 1903 build 18362.116 and Visual Studio Code. Now the integrated terminal only launches externally.
Pressing Ctrl + ~ results in this.
What am I missing? How do I get it to open integrated again?
EDIT
After working with VSCode team it is a verified bug. See the Github issue here. I posted the workaround as an answer here.
OK, worked through this one in VSCode repo issues.
For now, until it's fixed, turn off ConPTY integration in the User Settings.
💥💥💥
The issue now says use legacy console. To change the setting open a cmd prompt. Right click the title to bring up properties.
Then Uncheck 'Use legacy console'
To change the integrated terminal on Windows, you just need to change the terminal.integrated.shell.windows line:
Open VS User Settings (Preferences > User Settings). This will open two side-by-side documents.
Check if "terminal.integrated.shell.windows" has value "C:\\Bin\\Cmder\\Cmder.exe" setting to the User Settings document on the right.
Remove this line.
Ctrl + ~ will now open integrated terminal of VSCode.
If the above solution doesn't work then can you try below values and check if it works for you:
// Command Prompt
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"
// PowerShell
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
// Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
// Bash on Ubuntu (on Windows)
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
From the Command Palette (Ctrl+Shift+P), use the View: Toggle Integrated Terminal command.
Try custom shortcut:
[
{
"key": "ctrl+`",
"command": "workbench.action.terminal.toggleTerminal"
}
]
Had this problem fixed. Found the solution from the VS Code support.
for error:
Terminal exits with code 3221225786 (or similar)#
"This can happen when you have legacy console mode enabled in conhost's properties. To change this, open cmd.exe from the start menu, right-click the title bar, go to Properties and under the Options tab, uncheck Use legacy console."
source: VS Code docs

vscode automatically "source activate" everytime launches new terminal

Recently when I'm using vscode, everytime I launches the built-in terminal, it automatically uses "source activate base" to launch a anaconda python virtual environment. You can see the screenshot
I don't think I changed anything but it just came up randomly. Can someone help me out?
To prevent automatic activation of a selected environment, add
"python.terminal.activateEnvironment": false
to your settings.json file (it can be placed anywhere as a sibling to the existing settings). However, debugging or running Python code without any activated environment won't work.

How do I set the "elm-format" path within VSCode?

How do I set the "elm-format" path within VSCode?
I receive the following error:
I then installed the executable:
How do I now point VSCode to the elm-format.exe path as the error suggests?
Do I add it to the Language Specific Settings for Elm below?
// Place your settings in this file to overwrite the default settings
{
"window.zoomLevel": 1,
"files.autoSave": "off",
"elm.formatOnSave": true,
"[elm]": {
}
}
The elm-format mechanism is pretty rudimentary, and works as follows:
1) install elm-format for your platform (from github, as you've indicated)
2) add it to your PATH environment variable (i.e. PATH environment variable of the operating system, nothing to do w/ VS Code, etc). The idea is that if you open a command prompt/shell and type elm-format the system should be able to find it
3) set elm.formatOnSave in VS Code (as you've already done)
Now when VS Code saves, if you've installed, say, the elm extension, it'll invoke the elm-format command line utility (installed in 1 above)