How to get similar functionality to RStudio in PyCharm - python

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

Related

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 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.

Loading code from editor into PyCharm terminal

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?

Python Workflow like RStudio?

I use Python as my main programming language, sometimes switching to R for quick data-analysis tasks due to it’s huge library for statistical programming purposes (although pandas for python is great!). I guess that most R-Users go for R-Studio, which is like an IDE for R. There are probably hundreds of IDE’s for Python, but i’d like to stick with VIM and IPython. Although there is the vim-ipython-plugin, i can’t recreate the R-Studio workflow, which is mainly:
Write code in the source-editor
"push" or execute it within the console window via CTRL-Enter
after that, the results get displayed in the console window or the plotting window
When using the vim-ipython plugin, you can execute vim-lines via CTRL-S, but the results in the running IPython-Kernel/QTconsole are not updating. Instead, the output goes directly to a VIM window (<leader>s opens it, but the window closes all the time and isn´t able to display inline-graphics, like the ipython-qtconsole does).
I’m sure this isn’t a new "problem", but is there any setup for VIM and (I)Python, which mimics the RStudio behavior and integrates both the editor and the interactive interpreter like modern IDE’s do? Copying text from vim to the interactive interpreter can’t be the optimal solution, right?
The canonical way of doing this in vim is to run vim inside a gnu-screen or tmux session with the REPL in a second screen in the session. You can then use vim-slime to send code from vim to the REPL.

Categories