I've been trying to research this for a while, but can't find the answer. I'm using the keybinding shift+enter to send the line of code to the Terminal, but it only sends to the Python Interactive. It looks like VSCode should be able to figure out out where it should send the code automatically, but the only way I can figure it out is to uncheck...
Python > Data Science: Send Selection to Interactive Window
After doing this shift+enter would execute to the terminal.
I was curious if anyone has ran into this issue and fixed it without unchecking properties.
I'm a developer on this extension. By default the setting should be sending shift-enter to the terminal. So Send Selection to Interactive Window is false by default. We do have a popup that if you are executing a file with code cells in it (#%% markers) we prompt and ask if you want to send selection to the Interactive Window. If your setting was turned on it might have been that you said yes to this popup or changed the setting a previous time. Do you recall having changed the setting before?
Related
I know these are questions: this and this and this. I have tried all of these methods in pycharm, but they either a) not work or b) I get a weird character on my screen, that looks like a 0 with diagonal line going through it. I can't copy it for some reason, so I can't show you.
For instance this:
import os
from time import sleep
print("lots of text")
sleep(5)
os.system('cls')
What should happen in the above is tht the message should be displayed for 5 seconds then disappear, but all I get is that weird character... In contrast when I ran my python program from command line, it worked as expected i.e. the screen cleared. I am very confused.
So my questions are:
Why don't any of them work in pycharm?
What does work in pycharm?
Ok, so, I have been having this problem as well — after scouring the internet, the os commands work BUT you need to enable the terminal emulator.
In the PyCharm toolbar, click Run, Edit Configurations, and the toggle for "Emulate Terminal in Output Console" should be under Execution in the pop up. Emulate Terminal toggle
I had to get help from the PyCharm team on this one, so here's to them responding at lightning speed.
Answer
The cls command doesn't work on a standard pycharm project because it is an IDE and certain os commands don't work in the same way it would with the windows command line.
There is currently no way to clear the console output in PyCharm, other than to manually do it by using the cls command through the terminal in PyCharm or through a keyboard shortcut set through the pycharm preferences menu. You can try to emulate a keyboard shortcut, but this would be difficult, and unless you absolutely need it, I would not recommend clearing the terminal output after a program is run.
References and Additional Links
https://teamtreehouse.com/community/clear-screen-for-pycharm-as-if-it-were-on-console-or-cmd
I don't know in which version of PyCharm this was introduced. I guess it must have been after this question was asked.
The way to clear the PyCharm Python Console is by using the context menu. Right mouse click in the upper part of the console (where the lines with >>> prompts are closer together) and select Clear All.
Alse see this PyCharm Support Community article.
Incidentally, none of the questions linked to in the OP's original post relate to PyCharm and do not answer the OP's question.
cls only temporarily clears it. Next command brings back all previous messages. The best option is to right click on the Terminal and choose Clear Buffer
This may be a really basic question but I am not clear how to proceed. I have started using python in datacamp courses but now moving to my own terminal is giving me some issues. When I open VS code and open the file I want to work the terminal does not allow me to write, it just appears a path, I tried to run a simple code but it does not run, basically happen anything. Do you know if I have to do something specific before start running the code to enable the terminal?
import matplotlib.pyplot as plt
year = [1950, 1970, 1990, 2010]
pop = [2.519, 3.692, 5.563, 6.972]
plot1 = plt.scatter(year, pop)
plt.show()
And this is what I see on the screen, below the path highlighted in yellow the terminal does not allow to write
I Appreciate any suggestion, Thanks
The terminal is working fine, but there is currently a program running in it!
You called Python to execute your clase.py file. So, all input/output you do in the terminal will now go to/come from your Python program that you just called, not your shell.
You can either wait for the program to be finished (you will get another prompt then) or press Ctrl+C to abort your program. Since your program looks like it's outputting a plot somewhere, I'd assume it opens a new window for that - in this case, the terminal will return to the prompt once that window is closed.
If you need a second terminal to do something else while the program is running in the first, you can click the "+" button to open a second terminal (you can switch using the dropdown), or the "split" button right next to the "+" to open the second one at the side.
I was previously using the Jupyter extension for VS-code (https://github.com/DonJayamanne/vscodeJupyter) and could select my code and run it with the output being displayed in a 'Results' pane.
This no longer seems to work - when I for instance select a variable and run it the "Python 3 Kernel" status at the bottom flicks rapidly between busy/idle, but the variable is not displayed.
I see that the extension is now deprecated and instead one can run cells using the python extension, however is there any way to replicate this old functionality which was quite central to my workflow?
So we actually just added this functionality to the Microsoft Python Extension and it just shipped last night. If you are in a .py document with #%% cells defined you can hit shift+enter in a cell with no text selected to run that cell in the Interactive Windows. If you are in a .py file with cells defined and you selected text and hit shift+enter then just that text (not the whole cell) will get sent to the Interactive Windows. If you are in a .py file without cells defined and you select text and hit shift-enter that text will get sent to the normal python terminal as before. But you will now see a one time pop-up asking if you would instead like to send shift-enter commands in non-cell files to the Interactive Window instead. If you miss the pop-up you can also just change the Send Selection to Interactive Window command that we had added in the options.
In Spyder I can run only a part of code without running everything. I know that in PyCharm I can click right mouse button and "Execute Selection in Console", but it will be new execution without values and variables which declared before this part of code.
So, very often I need to run only few last lines of my code, with parametres and options that I already have.
you can try to use the interactive interpreter while in debug mode.
I find it to be very useful when trying to run code snippets in the program.
view the screenshot below.
You can use the "Run cell" functionality and the cell will be executed in the Python Console (the same way it does when right clicking "Execute Selection in Console"). To enable that I am aware of two options :
In settings (Ctrl+Alt+S) install the "PyCharm cell mode" plugin.
Then use ## to create code sections.
https://plugins.jetbrains.com/plugin/7858-pycharm-cell-mode
Create a new project in scientific mode (only available in PyCharm professional)
You can create code cells with #%%.
https://www.jetbrains.com/help/pycharm/matplotlib-support.html
In both cases, it creates cells that you can execute with the green "play" button like shown below :
IDLE is being very dodgy as to when it will actually show an Auto-complete menu. As of late it hasn't been working at all, or, more specifically, only works during an interactive session.
I've been using Code Blocks for C, and have gotten really used to the very nice auto-complete features, so it's a bit frustrating not having them -- especially while trying to learn a new frame work and what class is associated with which methods, etc, etc..
Is there an easy fix to get IDLE auto-complete working again? I'm using python version 2.7.
Is there perhaps a simple editor I should look into? I've tried Vim, which was a little too heavy for my simple needs, Ninja, which I couldn't get to work for anything, and Sublime text 2, which I couldn't get my wxpython stuff to play with. What would a nice option be? Anything similar to Code Blocks would be cool, although, I'd be perfectly happy with IDLE if it would consistently work!
REQUESTED CLARIFICATION:
OK, so it seems I may have some of my terminology backwards. By non-interactive, I mean, for instance, right clicking on a python file and selecting "edit with IDLE". This brings up what I guess could be described as a text editor. You can enter all you code here. Once ready, you then hit F5, or select Run, and it launches (what I've been referring to as) the interactive terminal. It's here that you can type in code, press return, and instantly have that code evaluated.
What my question is referring to it the former, the part of IDLE where you edit the code. Sometimes while typing, after a . it will display the available methods, or after an open parenthesis it'll give hints as to the values expected. but the thing is, sometimes it does these things, sometimes it doesn't.
The only thing i found so far is that if an editing session of IDLE is connected with python shell (called "interactive mode" in the question, i.e. after an attempt to run the edited script) then "non-interactive" IDLE can autocomplete based on values in interactive window. For example, if I type
a = [];
a.appen
and then hit < Tab > it will do nothing, but if I previously type
a = []
in corresponding python shell, IDLE will autocomplete correctly.
So my only suggestion is import same modules with same names in python shell window in order to make them "visible" for non-interactive IDLE editor.
I had the same problem with IDLE, because I want to learn Qt and therefore autocompletion is very useful.
As it says in the settings of IDLE, you can trigger the autocomplete with "Control + Space", e.g. after a "QtGui.". Then a menu opens where you can arrow-scroll through the entries.
using the 'IDLE Editor window', you need to save and execute your code first.
The application running, turn back to the Editor window to use the auto-completion.
In my case, I had to open Options menu -> Extensions tab on the editor and look to make sure AutoComplete and other relevant options were enabled. They actually were, but by just clicking on 'Apply' even though I dint have to change anything did the trick for me.
Sometimes it has to do with the time you have to wait to get a suggestions.
When you go to options > extensions > general at completions popup wait you can change it to about 500ms.
In my case it was 2000ms by default.