I'm currently trying out PyCharm (Python 3.5 from the Anaconda distribution) and can't find a way to run code in an already open console. As an example, consider the following code:
from time import time
now = time()
from inspect import signature
import numpy as np
import scipy as sp
import sympy
import sys
import matplotlib.pyplot as plt
print(time() - now)
If this is run in the Spyder IDE, the first run takes about 2 seconds, but subsequent runs take microseconds because the modules are already loaded. In PyCharm, every run takes 2 seconds. Is it possible to have PyCharm not reimport modules to run faster?
The only real difference is persistence. Console is like a playground for throwaway scripts. On the other hand, your editor allows you to write your code, and save it to a file.
The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes. and check the Special Variables list. The console is available for all types of Python interpreters and virtual environments, both local and remote.
PyCharm enables you to use interactive consoles, thus making it possible to stay within the IDE, without the necessity to switch to the shell.
My coworker refused to use PyCharm because she was used to this feature in Spyder and didn’t know that it does exists in PyCharm as Execute Selection in Console
feature which is typically have a shortcut combination of Alt+Shift+E.
Current PyCharm feature documentation does not mention that short-cut.
Update: As of 2020 documentation is updated and much more comprehensive.
If you have a different keymap you can check in setting window by searching Execute selection in console to see feature’s shortcut or perhaps even assign your own custom short-cut in Settings → Keymap like Ctrl+Enter which resembles interactive console-like experience for many Python developers who like to execute code selections to see outcome during development process.
According to docs here:
Select chunk of code you want to execute in console, right click and select Execute selection in console
or press Enter (enter won't work for vim extension).
Every time your selected code will be executed in same console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With