"Enter" doesn't work in VS Code for Python - python

I installed Anaconda. Somehow, afterwards, when I press Enter in Python files, it no longer works. This error shows up:
command 'pythonIndent.newlineAndIndent' not found
How do I solve this problem?

I had the same problem. I solved the problem by uninstalling an extension called "Python Indent"

Try checking your keybindings.json file, also disable all VS Code extensions and install them one by one. Maybe it's caused by some buggy extension.

uninstall python indent from vs code then again download the same extension.Hopefully now it works properly.

Search Enter in Keyboard Shortcuts and see if your wanted one is list there:
If not, search with your wanted effect that enter brings and see if you changed the keybindings, which you can see your customization in keybindings.json.
Or disable the third-party extension but only keep Python.
If the above don't work, you may reset VS Code.

One work around is "ctrl + Enter" instead of only pressing "Enter".

Related

I think ive setup vscode the wrong way or not able to find out a few root reasons for a few errors

why is this error there in the terminal?
i was trying to run a simple file after saving it yet it wasnt able to locate the file in the directory as mentioned, hence was giving the following error.
The simplest way to fix this is to remove : at the end of second line. It is a typo which kind of destroys rest of the code.
Delete your current terminal, or Ctrl+Z and press Enter to exit the current python interactive mode.
When your terminal looks like this you can use the play button to run the code.
When your terminal looks like this, it means that you have opened the python interactive terminal, where you can directly type the code and run it, but you cannot run the command.
By the way, as others have said there is a bug in your code, you need to remove the semicolon at the end of the second line.

Why do I have conda error in VS Code for running a python file?

I've been trying to get used to VS Code, and following their video tutorials.
I followed their debugging video and applied similar thing myself, however I get the following error about conda.
I don't see any print outputs on the screen, nor I can't use the input function in the code.
Is there something that I'm missing or doing wrong?
Thank you.
I couldn't find the reason, but found a solution: changing the interpreter from Anaconda to another one solved the problem for me. In order to change it:
Ctrl+Shift+P for command palette
Search for "Select Interpreter"
Select a working interpreter

Current shortcut to run Python in VS Code

I use VS Code on a Mac laptop. If I'm using Python I can run the code by pressing the little arrow in the top right,
However, I can't seem to find a keyboard shortcut for this. There is an old question, How to execute Python code from within Visual Studio Code, but all the answers there seem either to be obsolete or not to work on a Mac. One of them says that the F5 key should work, but my Mac has a useless touchbar instead of function keys so it's no help to me.
tl;dr is there a shortcut to run Python code on a modern VS Code installation besides F5, or an easy way to set one up?
I'm using Windows so i can't give you a specific answer. But Code > Preferences > Keyboard Shortcuts, search with keyword run python file, you will get related shortcuts.
I think you can bind the shortcut by yourself.
You can try with ctrl+shift+b in windows or ⌘+shift+b in MacOS.

Python with Xcode

I would have 2 questions:
I opened a python file with Xcode and it seems to have recognized it, but still the syntax coloring doesn't seem like python, so how to make it correspond ?
I tried to create a new Python project with Xcode following the instructions on this website: https://ericasadun.com/2016/12/04/running-python-in-xcode-step-by-step/ , but gives me "ERROR: unknown command "$(SRCROOT)/Work.py". I want to precise that it didn't give me the executable directly I had to select it myself in "/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9". I tried some suggested fixes as changing the "$(SRCROOT)/Work.py" by the path till Work.py : "/Users/user/Downloads/Python/Work.py". But still it persisted on the same error. So the question is how to make Xcode run a python code given the issues I encountered ?
Thanks !
So I fixed it by searching Work.py file and where I saved it. After that hit right click on the Work.py file and click on Get Info. Expand General: and then copy the text from Where:. Paste that in that Argument box and close the windows. Everything should work now.

How to change the behavior of indenting the new line after comma in Visual Studio Code?

I am a fresh python programmer. I started using VS Code because of its built-in terminal. (Before that I was using IDLE as an editor.)
My problem is, when I writing the code below in IDLE, all I need to do is to press enter to indent the new line to align with the previous variable.
someFunction(longVariable,
longString,
longWhatever)
In VS Code, it does this when I press enter:
someFunction(longVariable,
longString,
longWhatever)
Funny thing is when I align the "longString" by myself, It goes to the exact point where I want it to be as I press enter after comma. Like this:
someFunction(longVariable,
longString,
longWhatever)
How can I make it behave like IDLE?
I use it a lot.
In addition to installing the ms-python extension that #TheDude suggested, I had to install a formatter. The options are autopep8, YAPF, and Black. Here are the install commands (you only need one of them, I chose YAPF because I was getting weird results with autopep8):
pip install yapf
pip install autopep8
pip install black
Now, I could not get it working that it would auto-format when I return a line. There is a User Setting parameter called editor.formatOnType which I thought would take care of this, but it seems to have no effect. BUT, there is also a User Setting parameter called editor.formatOnSave that auto-formats your file every time you save it. If you change this in your user settings "editor.formatOnSave": true then every time you save your file, it gets auto-formatted.
You can also use the auto-formatting hotkeys and it will have the same effect:
Windows: Shift + Alt + F
Mac: Shift + Option + F
Ubuntu: Ctrl + Shift + I
Install the ms-python Extension.
This offers linting, intellisense, and code-formatting. I'm not sure if it's exactly like IDLE but I've been using it for Python development for several months and it does right by me.
Click this button
The enter Python in the search box and press enter
The Extension published by Microsoft is the one I recommend

Categories

Resources