Two instances of PyCharm

Question:

When working under Windows I can open as many MATLAB instances as I want (and instances of other Windows applications as well).

Can it be done with PyCharm?

I can’t open more than one for now.

Asked By: Benny K

||

Answers:

Considering the thread from their official website which can be found here, you can open multiple instances only if they use separate config/system directories (this can be configured in idea.properties inside the PyCharm installation directory). Alternatively, you can open multiple frames in one PyCharm instance.

Answered By: cdrrr

Go to File->Settings, Appereance & Behavior -> System settings, than find line "Open project in" and set "Ask"(Settings window screenshot), now you can File -> Open recent, and you will get ability to open another project in another window.

Answered By: Tagrenam

Yes, it can be done. Below is a walkthrough describing the necessary steps.

The problem
PyCharm isn’t developed to run a second instance simultaneously, like Visual Studio does. If you try to run a 2nd instance of PyCharm by holding down the SHIFT key while you left-click on its icon, it will just show up the first (and only) instance running. I found that just cloning (copying) the entire program files location is only the first part of the solution, because you also have to tell PyCharm to use a different set of runtime configuration (such as its cache etc).

Solution
The script below will create a copy of the existing PyCharm located in the "Program Files" directory. It will then overwrite "idea.properties" which you need to prepare once (see description below). Important: While the developers of PyCharm know it is possible, there is no official support running more than one instance at the same time.

I have created a batch script update2ndPyCharm.cmd. Before you use it, please read the instructions below the script:

REM Script to create 2nd instance of PyCharm from existing one
@ECHO OFF & CLS & ECHO.
NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (ECHO You must right-click and select & ECHO "RUN AS ADMINISTRATOR"  to run this batch. Exiting... & ECHO. & PAUSE & EXIT /D)
REM ... proceed here with admin rights ...

setlocal ENABLEDELAYEDEXPANSION & pushd .
set pyCharmDir=PyCharm 2023.2.5
set pyCharmSrc=C:Program FilesJetBrains!pyCharmDir!
set pyCharmTgt=C:Program FilesJetBrains!pyCharmDir! - Instance 2
ECHO Creating and updating 2nd PyCharm instance "!pyCharmDir! - Instance 2" ...
mkdir "!pyCharmTgt!" 1>nul 2>&1
xcopy "!pyCharmSrc!*.*" "!pyCharmTgt!" /S /E /H /R /O /V /Y
ECHO Overwriting settings to allow 2nd instance to run ...
xcopy "idea.properties" "!pyCharmTgt!bin" /Y 1>nul 2>&1
ECHO Done.
ECHO Now you can create a shortcut from pycharm64.exe (Explorer window will open now)
explorer "!pyCharmTgt!bin"

endlocal & popd

Steps for preparation:

  1. Create an Update directory, for example C:Update, create the batch file above there and copy the file idea.properties from C:Program FilesJetBrainsPyCharm 2023.2.5bin into the Update directory. Check the directories in case you have a different program files location (see Important notes at the end of this answer).

  2. Use your favorite editor to open the copy of idea.properties. Patch the following lines (i.e. edit it: remove # at the start of each line and ensure they look like this (keep all other values untouched):

    idea.config.path=${user.home}/.PyCharm_I2/config

    idea.system.path=${user.home}/.PyCharm_I2/system

    idea.plugins.path=${idea.config.path}/plugins

    idea.log.path=${idea.system.path}/log

  3. Save and close the file. Also make sure that PyCharm is not running!

  4. Update variable pyCharmDir in the batch script (it needs to be exactly the directory your PyCharm is installed into: here it is PyCharm 2023.2.5, then run the batch file update2ndPyCharm.cmd as administrator1) (Open admin shell, cd to the directory where the batch file and the patched idea.properties file is). If you don’t run it with admin rights, it will exit with an error message.

  5. A windows explorer will open. Create a shortcut of the file pycharm64.exe and put it to your taskbar or start menu. This will be your 2nd instance. The 2nd instance has the path C:Program FilesJetBrainsPyCharm 2023.2.5 - Instance 2 The first instance can be run from the original shortcut and has the path C:Program FilesJetBrainsPyCharm 2023.2.5.

Now each instance of PyCharm has its own location, settings, and shortcut icon (the one that you have created in the last step). You now can use each shortcut icon to run an individual instance of the IDE.

How does it work?

You might have noticed that this workaround creates an independent .PyCharm_I2 folder inside the user’s home directory (i.e. "${user.home}/.PyCharm_I2"). There it creates config, system, plugins and log subdirectories at the moment you start the 2nd instance for the first time.

The original config file idea.properties inside "C:Program FilesJetBrainsPyCharm 2023.2.5bin doesn’t use these path variables mentioned in step 2 (they are commented out), hence there is no conflict.

Note that – although rather theoretical – you could create more than 2 instances with this approach by cloning the program files directory again and giving the 3rd idea.properties file different subdirectories (e.g. "${user.home}/.PyCharm_I3").

Important:

  • Each time you need to update PyCharm, you will have to update both instances individually by selecting Help > Check for updates ... in each instance’s IDE.
    Make sure the IDE has restarted itself and all background tasks ("Updating…" in the footer) are finished. Run "Check for updates …" again, until Pycharm is telling you "You already have the latest version …".
    You don’t need to, but if you want to keep both instances identical, run the batch script update2ndPyCharm.cmd afterwards to copy the settings from the 1st to the 2nd instance. It is important that both IDEs must be closed when you start the script.

  • This script was created when version 2023.2.5 was out. Update the paths of the source and destination directories in the script according to your version! Note: Once installed, this directory will never change although your version gets updated.


1) You can modify the batch script to request admin rights automatically. Just replace the top 5 lines of the script update2ndPyCharm.cmd by the script which you can find here. (Copy everything from top of the script till but excluding the ::START section)

Answered By: Matt
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.