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.
Related
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
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).
Been using the safe and easy confines of PyCharm for a bit now, but I'm trying to get more familiar with using a text editor and the terminal together, so I've forced myself to start using iPython Notebook and Emacs. Aaaaand I have some really dumb questions.
after firing up ipython notebook from terminal with the command 'ipython notebook', it pops up on my browser and lets me code. but can i not use terminal while it's connected to ipython notebook server?
after writing my code in ipython notebook, i'm left with a something.ipynb file. How do I run this file from terminal? If it was a .py file, i know i could execute it by tying python something.py from the command line; but it doesn't work if i type python something.ipynb in the command line. And of course, I assume I hit Control-C to quit out of the running server in terminal first? or do I run the command without quitting that? Or am i doomed to test it in iPython and then copy and paste it to a different txt editor like Emacs and save it in a .py file to run it?
what good is the .ipynb file if i can't run it in terminal or outside the iPython Notebook browser? Could I get my code in a .py from iPython Notebook if I wanted to? (i assume I'll be able to easily run it in terminal by tying something.py then)
thanks in advance. I'm still very much trying to figure out how to use this thing and there aren't many answers out there for questions this elementary.
Yes, you can not use the same terminal. Solutions: open another terminal or run ipython notebook inside screen. If you use Windows you might want to take a look into this question
Notebook documents (ipynb files) can be converted to a range of static formats including LaTeX, HTML, PDF and Python. Read more about converting notebooks in manual
Notebooks are great, because you can show other people your interactive sessions accompanied with text, which may have rich formatting. And if someone can run notebook server he can easily reproduce your computations and maybe modify them. Check out awesome notebook on traveling salesperson problem by Peter Norvig as an example of what you can do with ipynb. Or this notebook. More examples are available here
You can run your IPython notebook process in background.
On Unix platforms you can perform that with (note the leading &):
ipython notebook &
Or after a "normal" run, hit [Control+z] and run the bg command
(some lecture).
you can convert .ipynb file into .py file using nbconvert
with Ipython notebook 2.x (some lecture):
ipython nbconvert --to python mynotebook.ipynb
with Ipython notebook 3.x (some lecture):
ipython nbconvert --to script mynotebook.ipynb
.ipynb contains your script AND results AND formatted text.
You can compare it to a literate script (but using "machine programming language").
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?
I've been trying to find this information online but I'm not getting the answer.
I've used RStudio and Geany for editing files before. Now I'm trying to use ViM to edit python and R files (I know there's RPy, but nothing to do with my problem).
I would like to know how can I have 3 terminals (could also be vim buffers, or screen windows) with one running ViM and the others running R and Python. When I execute a Python script, the terminal (window or buffer) with python shows the output. The same when I run R scripts.
I would appreciate insight on this as this is something that's keeping me from using ViM regularly. I would also consider a solution with terminator terminal multiplexer or guake terminal. Any information about sending code for scripting from one instance to another is welcome.
Are you looking for a way to have a REPL inside Vim? If so, Vim wasn't really designed with that in mind, though there are some plugins that try. Conque is an example.
Some things I use to have a quicker code/run/test iteration with Python:
IPython's %edit feature, which starts editing a script with $EDITOR and will run the script after you exit.
vim-ipython which can send/execute/recieve code via an IPython interpreter.
tmux which allows you to have multiple shells side by side, but with little interaction between them.
Vim-slime is a general-purpose solution to this I'm pretty happy about, it will send blocks of code to any tmux pane, meaning it works for any language.
https://github.com/jpalardy/vim-slime
Your requirements for online information may not have been spelled out in enough detail, since I seem to find a wealth of information on using ViM as an IDE for both R and Python:
R:
http://www.r-bloggers.com/r-with-vim/
http://www.vim.org/scripts/script.php?script_id=2628
http://www.vim.org/scripts/script.php?script_id=1048
Python:
http://wiki.python.org/moin/Vim
http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
Have a look at vim-ipython, a plug-in for Vim.
You need to download the source (linked above), and run the Vim command :source path/to/file/ipy.vim.
Start by running a new IPython session (e.g. using IPython qtconsole or IPython notebook) and then type :IPython into Vim. Your Vim is now connected to the IPython instance you just opened.
You can press F5 to run the whole python script in your Vim, or Ctrl+s to run the current line. Ctrl+s will also run whatever is selected if you're in visual (i.e. 'select') mode.