Visual Studio Code - Python interactive data science REPL with autocomplete - python

Since VS Code supports JupyterNotebooks natively with the Python extension (https://code.visualstudio.com/docs/python/jupyter-support) I like to launch the notebooks and see the outputs directly in VS Code.
The only issue I'm having with this is that the Python Interactive window is not that interactive, it just works to show the output of the cells.
Is there any way to allow autocomplete functionality in that console? Something more like an IPython console where I can hit Tab and see all the available options.

The answer is that this currently does not exist. The input box on the Interactive Windows is basically just a plain text input terminal (with colorization) currently. We do have a work item to track adding autocomplete here. If you want to watch or upvote that item it's located here:
https://github.com/Microsoft/vscode-python/issues/4170

Related

How to get similar functionality to RStudio in PyCharm

I normally use RStudio to do data science work. I load the datasets, and then write and try new code line by line, changing parameters, exploring the data, and executing small chunks at a time.
I'm currently using PyCharm for a project in Python, and it seems to be geared to software development, running and debugging entire scripts from start to finish, which is incredibly slow and frustrating when used to the RStudio mode.
Is it possible to have a similar data science environment to RStudio is it better to change tool to something else?
If you want to run code line-by-line you could try this plugin: https://plugins.jetbrains.com/plugin/11945-python-smart-execute.
If you want to change the default hotkey from "Ctrl+Shift+A" to default RStudio "Ctrl + Enter" you could do that here.
Also, here's a ticket about merging the plugin into PyCharm: https://youtrack.jetbrains.com/issue/PY-38919.
You can enable "Scientific Mode" in PyCharm. In this mode all code is executed inside the same interactive Python Console, all plots and tabular data are shown in a separate panel, there is a separate panel with Documentation. Also it supports code cells execution (code blocks inside *.py file separated by #%%), current line/file execution in Python Console (available in the context menu in the editor).
The full description is available here: https://www.jetbrains.com/help/pycharm/matplotlib-support.html

How to Auto-format Code in Python in NPP or Online

I do most of my Python coding in Notepad++. I would like a way to quickly and easily reformat my code using the default rules from PyCharm - things like spacing, number of blank lines between functions etc.
I find black playground too harsh for my requirements, and opening up PyCharm to paste code and reformat it defeats to purpose of using Notepad++ (for it's lightness).
So do you know of either a plugin for Notepad++ which does this (and I'm not just referring to Python Indent), or an online resource which applies PyCharm style formatting to pasted code?
PyCharm comes with a CLI, like documented here https://www.jetbrains.com/help/pycharm/command-line-formatter.html.
Alternatively and making the call slightly shorter: parallel to the mentioned there general batch file, you probably also have 'format.bat'. You can integrate this into Notepad++ via the [F5] button "Run...":
Put there
C:\__YourPyCharmRoot__\bin\format.bat "$(FULL_CURRENT_PATH)"
and press the [Save] button in this "Run..." dialog to assign a short-cut.
Pressing the newly defined short-cut on a saved and writable Python file should let Notepad++ ask you after a while (of running PyCharm in Windows cmd.exe) to reload the changed file .

Pycharm: Using Jupyter instead of prompt for debugging

When debugging a .py file within pycharms debug mode i can interact using a python prompt when hitting a breakpoint. Is there any way to use the current state of pycharm within a jupyter notebook istead of the python prompt?
It would make debugging quite a bit easier since you could reuse code snippets for debugging purposes.
I couldn't find anything about it, but for me it feels like it could be a thing.
Thanks for any help!
Based on this post, the functionality you are looking for does not exist. The key piece here is that you're trying to import an existing python interpreter into a new IPython kernel. However, from the post linked, you can attach a notebook to an existing IPython kernel with a little bit of work.
A possible solution would be for you to switch to using an IPython interpreter in PyCharm, then attach to that exising kernel in a notebook when needed (as described in the section above).

How do I add Multiple Python Interactive Windows in VS Code?

I am trying to create a second Ipython window in my VS Code Environment.
Sorry to say, but currently there can only be one Interactive Window open at a time. We do have an issue filed on allowing multiple windows here:
https://github.com/Microsoft/vscode-python/issues/3104
Which you can upvote or comment on if you would like.
The response above is longer up-to-date. Now, VS code supports multiple interactive windows: Open settings and search "interactive window mode".
You can select from single, multiple, per-file
see https://visualstudiomagazine.com/articles/2020/08/13/vs-code-python.aspx
To create another interactive window go to command pallete (Ctrl+Shift+p) and search for "Create Interactive Window."

How to save the python scripts made on Python console in Pycharm?

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.

Categories