I am writing python code and switched from spyder to VSCode and I'm wondering if there is a way to keep the variables in the memory outside of the debugging mode.
I want to keep the variables to look inside and/or to run just single lines/sections again without running the whole script.
I think you want a Jupyter notebook style form of programming.
There is a guide on how to use Jupyter notebooks in VS Code here.
I just started using jupyter for a python project. I constantly find myself adding an extra cell just to perform some basic try&error debugging. This way I omit the whole code of the cell is being executed but it still doesn't feel like the right way to do it.
Does Jupyter provide something like a static kernel terminal, for example always visible at the bottom of the screen, where I can simply paste code and execute runtime variables?
By the way: I did search but didn't find anything looking for static console, and terminal. Maybe I'm just looking in the wrong direction.
Thanks!
The jupyter console command will provide you with an interpreter environment that you can experiment with code running within the Jupyter environment outside of a notebook.
It's not exactly what you're looking for but may provide a better environment for testing and developing code that you can then paste into the appropriate notebook.
I have been writing scripts in Python console provided in Pycharm but now I need to save them on my desktop and run them at some later point. I can not happen to find any option to do so for the console scripts.
I don't think there is a way to save the contents of a console session within PyCharm (or any other editor that I know of). As #daladier pointed out in the comments, though, iPython may be what you are looking for. Using Jupyter Notebooks which are based on iPython you can create interactive cells in notebooks that behave similar to the console.
I've just started using PyCharm, and am consistently pleasantly surprised by its tools and configurability. I know that in PyCharm, you can load code from the editor into a Python console (see https://www.jetbrains.com/pycharm/webhelp/loading-code-from-editor-into-console.html). However, the remote console I'm using in PyCharm is very slow.
If I access python on the remote machine directly via ssh, it has no performance issues. As such, I'd like to just open the remote version of python via PyCharm's Terminal, and execute code in the terminal from my editor.
However, I haven't found any key bindings (or options) that let me automatically load code -- it's a manual copy and past process for now. When I try to create a keyboard shortcut to do this, the option isn't available. Is there a method to create a keyboard shortcut to load code from the editor into the terminal?
The only way to create such a shortcut by yourself is by writing a plugin to PyCharm. PyCharm plugins are written in Java, so I don't know whether this sounds like an appealing option for you. Alternatively, you can file a feature request at http://youtrack.jetbrains.com/ asking for this feature to be added.
Note that you can set up a run configuration that will run your code for you on a remote interpreter without going through a console. Have you tried this? Is it also slow?
Many python IDE's boasts of providing code-completion (code insight), PyCharm is one of those IDE's. However, it seems to me that the provided code-completion is extremely limited. Let me give you an example to make it clear:
import numpy as np
m = np.random.random((3,5))
m.
Hitting CTRL-space after 'm.' will not give me any code-completion, -no matter how hard I hit it ;).. I guess this is because the IDE would have to do type inference to know the type of the variable 'm', and that this isn't trivial in the domain of dynamic programming languages.
Now, PyCharm comes with a setting called "Collect run-time types information for code insight", which indeed sounds promising. However, it doesn't seem to fix the problem mentioned above.. I am still not able to get code-completion on the variable 'm'.
Thus far, I have only found one way to get code-completion on variables in PyCharm:
import numpy as np
m = np.random.random((3,5))
''':type : np.matrix'''
m.
In this example I am able to get code-completion when pressing CTRL-space after 'm.', and this is because I am helping the IDE by specifying the type of the variable with a docstring. I am, however, not satisfied with this way of getting code-completion, because it adds unnecessary verbosity to the code with all these docstrings (not to mention all the extra keyboard-typing)...
IPython to the rescue.. (maybe?)
Now, if we start IPython in a linux-terminal, and enter the first piece of code, we will be able to get code-completion all the way, -even for the variable 'm'. (where the code-completion in IPython is achieved by pressing TAB instead of CTRL-space)..
I don't have much experience with IPython, but I believe that I've heard something about IPython constantly executing the code in a loop or something like that...
I am thinking that it should be possible to use IPython to achieve REAL code-completion on all variables in the editor of PyCharm....
Is there a way to setup PyCharm to use IPython for code-completion?
Note that I am not satisfied with sending the code to a terminal window/console, or something like that, I want code-completion inside the editor of PyCharm...
I have looked at questions like this Adding ipython as an interpreter in Pycharm Ubuntu, but it seems to be about using IPython in the console, -not in the editor... There are also plenty of questions talking about code-completion in IDE's, but they all seem to have the same unsatisfying level of code-completion as PyCharm...
My setup
OS: Debian testing
python: Python3 and IPython3
IDE: Pycharm 3.0.2 professional edition
It cannot tell what returns are from functions(with out actually running the script, thats why ipython knows what it is (it has actually run the code and recieved back an object it can introspect)
if you want code completion without having to actually execute your script up to where you are entering text you have to do an extra step
import numpy as np
m = np.random.random((3,5))
assert isinstance(m,np.ndarray)
m. #now you get code completion (since the IDE now knows the class of m, without having to execute your script)
I had the same question, I found the answer here:
https://www.jetbrains.com/pycharm/help/using-ipython-notebook-with-pycharm.html
What you need to do is to create a ipython notebook in the project tool window. This is a file with the extension '.ipynb'. Right click on the directory where you want to put the file, select 'New-->File', enter a file name in the dialog box and give the file extension .ipynb. Open the notebook file and when you start to type something in the window, a drop down window appears with objects in the namespace plus any commands that start with the letters already typed.
To achieve iPython like functionality in pycharm, you can do it two ways:
setup a breakpoint, and debug your code. when it reaches the breakpoint, go to the console tab right below the editor, and launch a command line by clicking the button that says show command line
Launch a python command line from your console (without running debugger), by clicking on Tools, Run Python console