Terminal shows only an empty non-editable cursor in VS Code - python

Something has changed in my VS code that doesn't allow me to type in my Terminal. I'm sure it's a config issue but not sure where to look. This is what I see:
I tried changing my Python version or shell showing on the terminal but no luck. How can I fix this?

I had the same problem when learning some PHP. After clicking on every option modifier available, I found that in the bottom Status Bar, there was a "Normal" view on the left.
Right-clicked, and selected "Hide Normal" and the cursor and my ability to write code came backImage of my VSCode showing VIM cursor
In the end I found that I had the VIM extension enabled and had not used its variables correctly. Either uninstall the extension or use its commands

Related

Using plotly in WSL changes the font (console window changes to raster), and won't work at all in VSCode

I've attempted to work a bit more in WSL recently (I've got the most up-to-date version of WSL2 and the Windows 11 insider beta, both of which I updated today)
Everything works great! But plotly has been giving me issues. When I run it from within VSCode (making sure Python Interpreter is set to my correct environment), it spits out the following error:
tcgetpgrp failed: Not a tty
It then opens a tab in my default browser, but it just hangs until eventually failing to connect
Alternatively, if I run it directly from the WSL console (no VScode), it still gives the same error as above, but it DOES correctly open a window in my web browser. It also, for some reason, changes the font of the console?
I'm not 100% sure what the problem is here. I've used WSL for awhile, and never had any issues with displaying plots and things as needed (though, historically, I've used matplotlib... this is the first time I've tried using plotly, but I've used it without problem on native linux and native windows).
Has anyone else had this issue? Or one similar to it? Any idea on what might be wrong?
Figured this out after a bit of reading on other projects that use plotly. The fix is actually very simple, and just requires adding:
export BROWSER="/mnt/c/path/to/browser.exe"
To your ~/.bashrc file. For example, for me this was:
export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"

Having Issues with Python debugging in vscode

I am pretty new to all this so bare with me, I am confused on what is going on with my setup to debug my python code. I have the most current updates for vscode, and the latest python 3 (3.8.5 64-bit). However when I try to start a debug, I get an time out error along with "Command 'cmd' not found, but there are 16 similar ones." Any ideas on how to fix this?
Try to reset your default terminal with the following steps:
press Ctrl+Shift+` to open a new terminal;
click the drop-down menu and choose Select Default Shell:
select Command Prompt:
Then reload window to make the setting work. You can try this to see if the problem goes away.

VSCode Jupyter: is there a way to make python interactive window work as default console?

I've recently switched to VSCode, and am wondering if there's a way to make the Python Interactive Window from the Jupyter support in VSCode work like the console in Spyder where I just have to select code and press ctrl+enter to send it, without having to create cells everytime.
For now I'm resigned to work with the Terminal until my code is clean and then create a cell when I have reusable code, and would like to just work directly with the PIW.
You can always change the default console setting by:
Opening the Command Palette (⇧⌘P)
Typing "Preferences:Open Settings (JSON)
Edit this line:
"python.dataScience.sendSelectionToInteractiveWindow": false
You should be able to do this with the latest python extension. The select the code you want to execute and press shift-enter. Is that not working?
For me (now) interactive mode runs after setting "jupyter.sendSelectionToInteractiveWindow": true
#FranciscoRZ. You should have seen a popup option for this, but if it didn't come up for you it can just be manually set in VSCode options. Just change this guy here:
Python->Data Science: Send Selection To Interactive Window
That should get you what you are looking for.
OP's Note: Accepting this answer because it will be the right anwser starting with the February release of VS Code Python
If you have the notebook saved as a python percentage script (which is more git friendly)
each "cell" will be delimited by # %% and the default run command is "Shift+Ctrl".
Later once you are working in the interactive window, If you want a particular cell you wrote on the fly to be in you script, there is one button which says "Paste code into file" right next to the recently executed cell in the interactive window.
And in case you are using the notebook for the sake of being able to later export it to html or pdf, once executed in the interactive window, there is an export button as well.

Python in VSCode: How do you run a previous command?

I'm kind of new to software development. Outside of VSCode, I can open up a terminal (let's say PowerShell), run python in it, type in a command (like 2+2), be able to click the up arrow key to find my previous command so that I can run it again.
If I run PowerShell in VSCode and do the same thing, nothing happens when I click the up arrow where I would expect my previous command to be cycled.
Is this a problem with my Python or VSCode? I've been looking for a solution for this but haven't found many useful topics on this.
This was going to just be a comment but its too long. Sorry it isn't more informative than it is. This is kind of an odd problem because VSCode isn't a true IDE. It doesn't have its own shell and just hijacks your powershell or bash terminal, depending on which OS you are using. You should be able to use your up and down arrows just like you can in powershell. I have tested it on my own VSCode installation and it works fine for me. If it's a problem, it's not with python, since VSCode will interact with the terminal the same way no matter which language you are using it for, so its probably with VSCode or your terminal. I have heard of others having issues with up arrow autocomplete in bash, so if you are connecting to a bash terminal that could be it, but I've never heard of it glitching in powershell. I'd say check which terminal you are using, see if the problem persists when you change terminals, and try reinstalling VSCode if it does. Past that, I don't know what to tell you.
I found a work-around. For me, neither git bash, nor PowerShell allowed up/down arrows for history switching within a python shell. So here it goes.
Ctr-Shift-P opens VSCode commands
Python: Create Terminal does not actuallt start python, but it does launch powershell in a mode that will enable us to succeed
py starts python shell with working up/down arrows!

Arrow keys in Putty returning ^[[A ^[[D ^[[B instead of moving the cursor

Has anyone else ever had this error in PuTTy?
For example, pressing the Up Key now produces:
>>> ^[[A
Google doesn't let you search for special characters so I'm stumped at finding existing version of this problem.
EDIT:
So this happened after I pasted in some unicode (when, I think, the translation was already set to utf-8).
I've checked the Change Settings dialog box for different settings than my other open PuTTy windows, but the settings appear to be identical.
EDIT2:
This is fixed by restarting PuTTy, but still a nuisance.
EDIT3:
How to replicate the exact same bug:
Open a putty terminal to a linux PC (I'm using RedHat)
Open Python 2.7.* - using the command python2.7 (note: error does not appear in 2.6)
import codecs
Now use the arrow keys, and these bizarre characters appear.
In my experience that's because "bash" is not running. Simply run "/bin/bash" to enjoy colors, history and more.
I've found that specifying "The Function Keys and Keypad" option to match your operating system resolves many issues.
[Putty]
Terminal -> Keyboard --> RadioButton "Linux"
(if you're using Linux) and then you can start your session
You could try changing the 'Application Cursor Keys' mode. It's in the Terminal->Keyboard subsection of the initial configuration window (these settings may potenitally be overridden by your server).
http://the.earth.li/~sgtatham/putty/0.55/htmldoc/Chapter4.html#S4.4.4
Just run the simple bash command or sudo bash in ssh. It usually works.
For those interested in the issue, had same simptoms in a virtualenvironment, resolved the issue with
pip install readlines
See following answer for details.
Terminal >>> Local line editing >>> Force off
See also

Categories

Resources