Question
Error highlighting and autoformatting can be great tools to help one create great notebooks. I am trying to change the settings on the VS code to allow me to autoformat to pep8 in my python notebooks.
On this page for Jupiter notebooks have found that I have to put some lines in my .json files in the settings>preference of VSCode in order to do this. I am particularly interested in changing my code to the pep8 coding convention and also adding linting in order to highlight errors.
linting (error highlighting)
autoformatting (autopep8)
I am using VS Code on Ubuntu 18.04. Below is my attempt that led to an error "Code language not supported or defined".
Attempt
After installing the Python extension and the autopep8 extension in VS code and running
pip3 install autopep8
I got an error message and was unable to use pep8.
If you may know how to set up an efficient working environment in VS Code for Jupyter notebooks I would really appreciate any assistance
Summary
How to set up:
linting (error highlighting)
autoformatting (autopep8)
in VS code for python notebooks.
Edit 1:
I also tried running autopep8 in the command palette and got the error
Command 'autopep8' resulted in an error (Running the contributed command: 'extension.sayHello' failed.)
Nbextensions are notebook extensions and only work within the notebook itself. VS Code does not support native notebooks so these extensions won't work at the time. They are planning to add it in future releases per link
Related
I'm now trying to run qiskit visualization functions(e.g. .draw() methods) in vscode.
I use latest version of Python, 3.11.1, and followed Getting Started Qiskit in here.
Also I installed qiskit extension in vscode.
However, when I run a qiskit code, the visualization functions don't work, even though code is compiled successfully.
I checked visualizing modules(mathplotlib, etc.) were installed.
I tried to re-install Python and vscode, including downgrading Python to 3.8. And it didn't work.
Additionally, qiskit-chemistry and qiskit-aqua installation warnings are pop-upped, but installation doesn't work.
I really don't know it is related on this problem, but I think maybe it's not since qiskit-aqua is deprecated.
The following screenshot is result of the qiskit test code.
result of running
draw() and plot_histogram() doesn't work as you can see.
How can I fix this problem?
These functions are meant to be used in Python Notebooks - they won't show up in normal .py files. Try using VSCode's Jupyter Notebook (.ipynb files) feature instead.
I'm using VSCode to create some Python scripts for a personal project. I have used VSCode without any problems in the past but I'm running into some errors now and can't figure out why.
At first I had conflicting Python versions - on the bottom bar it was Python 3.10.2 and when I use the version command in the Terminal I'm getting Python 3.9.7. Originally, I was getting errors that certain libraries were not installed - even if they were - but when I changed the bottom bar version to Python 3.9.7 ('base': conda) which is the same as the version command result - I no longer get that issue.
Instead, I now get an issue that consistently returns something like the following:
File "<stdin>", line 1
/Users/...
^
SyntaxError: invalid syntax
I can get things working on a Jupyter notebook but when I want to use scripts and keep work in folders this is causing a huge problem. Does anyone have an idea what I can do here to resolve?
https://github.com/microsoft/vscode-python
Open this link and install this extension.
Also, a step-by-step procedure is given.
A Visual Studio Code extension with rich support for the Python language (for all actively supported versions of the language: >=3.7), including features such as IntelliSense (Pylance), linting, debugging, code navigation, code formatting, refactoring, variable explorer, test explorer, and more!
Python extension does offer some support when running on vscode.dev (which includes github.dev). This includes partial IntelliSense for open files in the editor.
So, I've been using VSCode for Jupyter notebooks for almost a year and a half now, and it always used to work normally, but a couple of days ago it just got broken, and I don't know why. Here's what I mean:
Jupyter Notebook on VSCode
As you can see, there's no syntax highlighting, and autocompletion doesn't work at all... but if I run the code, it does run perfectly.
It works normally in Python scripts though:
Normal Python Script
Relevant Extensions I've got:
Jupyter (+ Keymap & Notebook Renderers)
Python
Pylance
I've got a bunch of others for C++ and Java.
Also, I've noticed that both Jupyter and Python extensions give an uncaught error, here's what I mean:
Jupyter Extension Error
Python Extension Error
I have no clue what any of this means. I've tried uninstalling and re-installing the extensions, re-installing VSCode, resetting settings.json and restarting my laptop, nothing worked.
Any help will be highly appreciated. Thanks
Do you have installed the extension of Dependency Analytics? You need to disable it.
Some people have run across the same problem, you can refer to here.
Issue: I am having issues with the environment and version of Python not matching the settings in VSCode, and causing issues with the packages I am trying to use in Jupyter notebooks. I am using a Windows 10 machine with Python 3.9.1 installed (including older versions), with Visual Studio Code 1.52.1 . Short summary - I install a package using pip. My guess is that it associates with the latest version of Python. I set up an interpreter in VS Code for that version of python, and try to import the package. The package is not found. If I call sys.version from the Jupyter notebook, I see that a default version of Python is running (3.8.5). The simple notebook throws an error because it cannot find that package that I installed with pip.
Screenshot that shows the associations:
This error is reproducible with only the
import pygmt
command in the notebook, i.e. it does not depend on the other packages imported.
Question: How can I control the version that Jupyter notebooks will run in VSCode if changing the interpreter doesn't work? Every other issue like this that I have found was due to not choosing the correct interpreter. In this case, I have. Why is it not running that version of the interpreter?
Thank you.
Edit
This edit is in response to #Jill Cheng's answer (see my comment below for tl;dr). I can change the interpreter (lower left corner of VSCode) to match the default that VSCode wants to run. No problem.
But there still are problems.
I cannot install pygmt, the targeted package, into this version of Python (see the command in in the terminal).
I cannot make VSCode operate in the opposite direction - i.e. I can never get it to run Python 3.9.1 even when that is the interpreter I chose.
I have reinstalled VSCode now several times, and Python 3.8.5 seems to always be the default. To me, the easiest solution seems to be changing the default Python version of VSCode - in fact, isn't that the point of selecting an interpreter? It is more nebulous to me why I cannot install pygmt into Python 3.8.5, and I don't know if it is beneficial to have multiple different versions of Python all with different packages (or is this just what Python users deal with daily?).
In VS Code, the Python kernel (Python environment) used by Jupyter notebook can be independent of the Python environment we selected in VS Code (shown in the lower left corner of VS Code).
As the output in the screenshot shows, the Python kernel of Jupyter you are using is "Python3.8.5", but the module "pygmt" is not installed in this environment. (Jupyter uses the last selected Python environment by default.)
Solution: Click the Python kernel on the upper right in the Jupyter notebook, and select the python environment where the module "pygmt" has been installed. In addition, it is recommended that you reopen the jupyter file after switching Jupyter's Python kernel so that it can reload the new python kernel.
Reference: Jupyter notebooks in VS Code.
I am using Visual Studio Code (VSC) as my IDE. My computer just updated to Catalina 10.15.2 (19C57) and since the update, now VSC is not highlighting syntax errors. The extensions I have seem to be working and it recognizes my miniconda python environment.
Is there a solution for this yet? I was avoiding Catalina as I know it has caused lots of errors, but now that I was forced to install it I need a solution as I love VSC.
I also had the same problem for typescript react files. Tried many things and nothing worked. Finally I checked the extensions I've installed for typescript react. Disabling JavaScript and TypeScript Nightly extension worked for me
In my case, the Catalina installation didn't remove my Python installation.
After checking as suggested by #Brett Cannon in his comment, the update to Catalina uninstalled some extensions from VS Code. These are not available in the VS Code extension Marketplace anymore, so there must be an issue regarding compatibility. I fixed it after I opened my command palette (Command + Shift + p) and typed python: select linter. Then selected pylint, selected the install with conda option, Close/Open VS Code and now it's working(though it's still not shown in my extensions section in VS Code). It's necessary to point out that you will have to install pylint in every Python environment you are using. In my case I have multiple Conda environments.
It's very specific but for me it was a missing semicolon in my css (styled-component). I use styled-components in react and it didn't throw an error for missing semicolon but highlighting was suddenly gone.
I had given up and left it that way until I came up with the solution quite by accident.
If you were using the global install of Python then that was removed in Catalina which would break your virtual environment. A new install of Python and recreating the virtual environment should fix things.
Had similar issue on new vscode setup - my problem was rather that eslint warnings are not being highlighted, only errors.
After opening my eslint setup for the project - .eslintrc.js file, saw message saying that eslint needed permission accessing some files, which I did by clicking the lightbulb next to module.exports and hitting accept button.