I am using a third-party Python client that can connect to different servers using some arguments.
In PyCharm I defined under
Python Console one of these and all works fine.
I would now like to add other Python Consoles that point to the interpreter with different interpreter options. Unfortunately the New Console button only lets me add one type.
All other Stack Overflow questions relate to different interpreters.
The integrated PyCharm console is a client-server that launches a new
pydevconsole.py process each time you press the
New Console button.
Unfortunately the New Console button only lets me add one type.
There are 2 ways to do this. One is simple the other is complex.
The simple way.
If you change the console settings at
Build, Exection, Deployment
Python Consolebetween each time you press the
New Consolebutton then different consoles will be launched with the different interpreter options, arguments, etc, that you configured.
The various consoles are launched with differing settings in each tab. The potential problem is that having to change the settings manually can become repetitive if you want to launch many consoles with different settings. Another problem is that if you press the
Rerunbutton the new console will be launched using the current settings, not the ones you configured the first time you launched it.
The complex way.
Try to create a new project (for a clean example). The console settings are stored in the project’s configuration file in
.idea/workspace.xml. Here’s an example of the default XML entity right after project creation:
<component name="PyConsoleOptionsProvider"> <option name="myPythonConsoleState"> <console-settings custom-start-script="import sys; print('Python %s on %s' % (sys.version, sys.platform)); print('a test') sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS]) " module-name="tmp_test" is-module-sdk="true"> <option name="myCustomStartScript" value="import sys; print('Python %s on %s' % (sys.version, sys.platform)); print('a test') sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS]) " /> <option name="myUseModuleSdk" value="true" /> <option name="myModuleName" value="tmp_test" /> </console-settings> </option> </component>
The more complex solution would be to write a Python script, configure it as an external tool, pass in the IDE’s
ProjectFileDirmacro appending the
.idea/workspace.xmlpath, and have that Python script change the console settings’ XML element by directly editing the
.idea/workspace.xmlfile. Finally you can bind a keyboard shortcut to the external tool.
This would allow you to switch the console settings (cycling through your predetermined settings) with 1 keyboard shortcut, after that the
Rerunbuttons would work seamlessly the way you want. (I wrote a step-by-step example of this technique in this answer.)
Both solutions can get the job done. Which one is better depends on how often you need to launch/relaunch consoles with different settings.