Is it possible to have a keyboard shortcut to move the caret from editor to console and back in pycharm? I can switch the focus between editor and console using CTRL+TAB, but that doesn't allow me to start typing in the console unless I click in it.
I am using the linux community distribution.
I'm on MacOS and PyCharm 2018.2. Doing Ctrl+Tab+P opens up console and focuses on it so I can immediately start typing.
Update: You can also set your own key map: Tool Windows/Python Console. Hitting Esc will focus you back on the editor window.
The key is to hit the TAB key once (potentially twice) after you move into the Python Console (via whatever shortcut you specify in the keymap).
I think it also depends on whether the Python Console is docked - looks like it doesn't work if the Console is in another Window. So my current setup is having the Console docked:
You can use Alt + 4 or Alt + 5 where the digit is the window number. And then to refocus back to the edit you press Enter.
A couple of years later but i found my self in this situations, i believe the other answers are good enough for some but they lack some important information or at least i didn't found it.
You need to look for the term Python or debug console under tools if you want to focus to the console with the caret at it, add a keymap value for that (in my case i added ALT+2), do NOT use the python console under tool windows, for that it will focus on the python console but not the caret at it.
(done with pycharm 2020.1.1 in a ubuntu 20.04 lts machine)
Related
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.
What are the key differences between Python's IDLE and its command line environment? IDLE looks nicer, of course, and has some kind of GUI...
Moreover, is IDLE treated the same as the shell? I mean, the shell is the middle layer between the user and Python's interpreter?
They are both the same thing but, IDLE is made to write python code so its better if you can to write on IDLE. You can also try Notepad++ its a pretty good program to write code on.
I am not sure what you question is, but here is a Windows-7 oriented answer of similarity and difference. In the start menu for Python x.y, you can select 'Python x.y (x bits)' to run python interactive in a text-line-oriented console window provided by Microsoft. The console handles key presses and mouse movements and clicks. When you hit , the console sends the line of text to python, which is waiting for input on sys.stdin. When Python processes the line, it sends output to sys.stdout or sys.stderr. This includes '>>> ' and '... ' prompts. The console displays the text for you to see.
In the start menu, you can instead select 'Idle ...'. Unless you have previously selected a different startup option, python run Idle code which uses the tkinter module which used tcl/tk to run a graphical user interface that somewhat imitates the console. The tkinter/tk gui handles key and mouse input and displays output. In both cases, some software besides the Python interpreter itself handles interaction between you and Python.
Some important differences:
Cut, copy, and paste work normally. The Windows console is crippled in this respect.
Idle colors input and output. The Windows console does not.
Idle can display all unicode BMP (the first 64K) chars. The Windows console is limited by code pages.
For 1, 2, and 3, the console of other OSes may do as well or better than Idle.
Idle lets you enter, edit, send, and retrieve complete statements. Interactive python with Windows console only works with physical lines.
Update, 2017/11:
Item 1 above: At least on current Win10, cut, copy, and paste work normally.
Item 3 above: At least on Win10, unicode works better in Command Prompt with 3.6+.
New item 5: The IDLE doc section, also available as Help => IDLE Help now has section '3.3. IDLE-console differences'.
IDLE is a very simple Integrated Development Environment. It runs the same python, libraries etc. as commant-line.
Even more basic (with less features) is IPython. Full feature IDE for Python is, for example, Eclipse with PyDev plugin, or LiClipse.
Python IDLE is where you write your program/s and Python Shell is where you run your program/s.
Are there any smooth way to run Python scripts in the PyCharm's console?
My previous IDE - PyScripter - provides me with that nice little feature. As far as I know PyCharm has 2 ways of running script in console:
1) Select a bunch of code and press Ctrl+Alt+E.
2) Save the code in a file and import it from the Console.
Are the any way to do it by pressing "Run" or "Debug" buttons? I need to see the result of my script in the console and all variables available to manipulate.
In the Run/Debug Configuration, add -i to the interpreter options. This will stop it from closing a python session even after a successful run. I.e. you will be able to see all the variable contents
Run -> Edit configuration -> select the script you want to run and give it a display name -> OK
Now you can run it with the green "Run" button. The green bug button (next to the run button) will run it in debug mode.
Remark: next to the run button you can monitor the script/configuration you run by selecting it's display name.
If you create run-time configuration then after pressing the run button (green "play" icon) you will get the desired result: your code will give you output in a console which opens atomatically at the bottom.
You can create many different configuraions for run and debug within a single project.
Here is a link from PyCharm's web help which covers the run/debug configurations:
http://www.jetbrains.com/pycharm/webhelp/run-debug-configuration-python.html
A possible way of manipulating the variables using debug mode and evaluate expression window is added in comment but I missed one detail: to see the result of your interactive code execution you have to switch from Debugger to Console output; mode tabs are on the top-left side of the bottom pane.
The way I do it is a create my script in the editor, call it myfirst.py, eg
print "Hello"
a= 1234
then in the console I run:
reload (myfirst)
To check on the variables use:
>>> myfirst.a
Not perfect but that's pyCharm for you. If you want a pyScripter like experience which I think is more useful you can try spyder2.
It may also be a good option for you to use the magic command
%run scriptname.py
in the ipython console (including the %-character). Compared to Cntrl + Alt + E you also get clean information on errors in your code.
Due to autocomplete it's also typed in a second and you can use this in any environment with an ipython shell. For me as a scientist who often uses python to explore data, this is a good option.
With your program in the editor:
Run - Edit Configurations
Then under Execution check the box for "Run with Python console".
When you run the program from the green arrow it will run in a console. After the run all your objects are available to examine and play with.
PyCharm keeps a command history for it's interactive Python console.
Is there a way to access this history with some sort of search instead of just browsing the entries with the arrow keys in the interactive console window?
My environment: PyCharm 2.7 EAP (124.138) on MacOS X 10.8.2.
As of PyCharm 3.1, while in the console, press ⌥⌘e, the "Browse History" window will come up, start typing to search for specific commands
Not available yet, please vote for the related feature requests:
PY-7922 In console, search history by typing prefix and pressing the "up" key
PY-5011 Ctrl+R in console should invoke history search like in bash
Nowadays, there is "Browse Console History" button located to the left of python console. It works on all OS where PyCharm works.
In Windows and Linux there is Ctrl+Alt+E which does exectly the same, but it may not work on Linux if it is overriden by system hotkey Alt.
In Windows you can use Ctrl Alt e
Because of vision problems, I have to keep the font in my Python programs in pycharm larger than the default setting. When I execute any program, the run window comes up at the bottom and every time I have to start working on the Python code in the editor window, I have to close the run window using a mouse.
Is there a way to close it using the keyboard shortcut? I could not find anything in the key map but there are so many settings that there is a chance that I may have missed it.
I also tried with using the distraction free option and it works very well. However, when I tried to find something within the code, it does not bring up the in-line window that allows me to type the keyword is searched for.
Please suggest if there is any way to close the run window or if there is any workaround so that I can return to working in a larger editor window.
Thank you for any inputs
shift+esc will hide the run window from within PyCharm.
If you want to access the run menu use: ctrl+shift+A
You can get a helpful cheatsheet of commands from within PyCharm by going to help -> Keymap Reference. This will provide the default key mapping for Windows and Linux
Have a look at Preferences -> Keymap under Tool Windows -> Run.
On Mac it is CMD+4.