<h1>Setting up PyCharm with Evennia<aclass="headerlink"href="#setting-up-pycharm-with-evennia"title="Link to this heading">¶</a></h1>
<p><aclass="reference external"href="https://www.jetbrains.com/pycharm/">PyCharm</a> is a Python developer’s IDE from Jetbrains available for Windows, Mac and Linux.
It is a commercial product but offer free trials, a scaled-down community edition and also generous licenses for OSS projects like Evennia.</p>
<p>First, download and install the IDE edition of your choosing.
The community edition should have everything you need,
but the professional edition has integrated support for Django which can help.</p>
<sectionid="from-an-existing-project">
<h2>From an existing project<aclass="headerlink"href="#from-an-existing-project"title="Link to this heading">¶</a></h2>
<p>Use this if you want to use PyCharm with an already existing Evennia game.
First, ensure you have completed the steps outlined <aclass="reference external"href="https://www.evennia.com/docs/latest/Setup/Installation.html#requirements">here</a>.
Especially the virtualenv part, this will make setting the IDE up much easier.</p>
<olclass="arabic simple">
<li><p>Open Pycharm and click on the open button, open your root folder corresponding to <codeclass="docutils literal notranslate"><spanclass="pre">mygame/</span></code>.</p></li>
<li><p>Click on File -> Settings -> Project -> Python Interpreter -> Add Interpreter -> Add Local Interpreter
<h2>From a new project<aclass="headerlink"href="#from-a-new-project"title="Link to this heading">¶</a></h2>
<p>Use this if you are starting from scratch or want to make a new Evennia game.</p>
<olclass="arabic simple">
<li><p>Click on the new project button.</p></li>
<li><p>Select the location for your project.
You should create two new folders, one for the root of your project and one
for the evennia game directly. It should look like <codeclass="docutils literal notranslate"><spanclass="pre">/location/projectfolder/gamefolder</span></code></p></li>
<li><p>Select the <codeclass="docutils literal notranslate"><spanclass="pre">Custom</span><spanclass="pre">environment</span></code> interpreter type, using <codeclass="docutils literal notranslate"><spanclass="pre">Generate</span><spanclass="pre">New</span></code> of type <codeclass="docutils literal notranslate"><spanclass="pre">Virtual</span><spanclass="pre">env</span></code> using a
compatible base python version as recommended in <aclass="reference external"href="https://www.evennia.com/docs/latest/Setup/Installation.html#requirements">https://www.evennia.com/docs/latest/Setup/Installation.html#requirements</a>
Then choose a folder for your virtual environment as a sub folder of your project folder.</p></li>
</ol>
<p><imgalt="Example new project configuration"src="https://imgur.com/R5Yr9I4.png"/></p>
<p>Click on the create button and it will take you inside your new project with a bare bones virtual environment.
To install Evennia, you can then either clone evennia in your project folder or install it via pip.
The simplest way is to use pip.</p>
<p>Click on the <codeclass="docutils literal notranslate"><spanclass="pre">terminal</span></code> button</p>
<li><p>Type in <codeclass="docutils literal notranslate"><spanclass="pre">pip</span><spanclass="pre">install</span><spanclass="pre">evennia</span></code></p></li>
<li><p>Close the IDE and navigate to the project folder</p></li>
<li><p>Rename the game folder to a temporary name and create a new empty folder with the previous name</p></li>
<li><p>Open your OS terminal, navigate to your project folder and activate your virtualenv.
On linux, <codeclass="docutils literal notranslate"><spanclass="pre">source</span><spanclass="pre">.evenv/bin/activate</span></code>
On windows, <codeclass="docutils literal notranslate"><spanclass="pre">evenv\Scripts\activate</span></code></p></li>
<li><p>Type in <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span><spanclass="pre">--init</span><spanclass="pre">mygame</span></code></p></li>
<li><p>Move the files from your temporary folder, which should contain the <codeclass="docutils literal notranslate"><spanclass="pre">.idea/</span></code> folder into
the folder you have created at step 3 and delete the now empty temporary folder.</p></li>
<li><p>In the terminal, Move into the folder and type in <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span><spanclass="pre">migrate</span></code></p></li>
<li><p>Start evennia to ensure that it works with <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span><spanclass="pre">start</span></code> and stop it with <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span><spanclass="pre">stop</span></code></p></li>
</ol>
<p>At this point, you can reopen your IDE and it should be functional.
<aclass="reference external"href="https://www.evennia.com/docs/latest/Setup/Installation.html">Look here for additional information</a></p>
</section>
<sectionid="debug-evennia-from-inside-pycharm">
<h2>Debug Evennia from inside PyCharm<aclass="headerlink"href="#debug-evennia-from-inside-pycharm"title="Link to this heading">¶</a></h2>
<sectionid="attaching-to-the-process">
<h3>Attaching to the process<aclass="headerlink"href="#attaching-to-the-process"title="Link to this heading">¶</a></h3>
<olclass="arabic simple">
<li><p>Launch Evennia in the pycharm terminal</p></li>
<li><p>Attempt to start it twice, this will give you the process ID of the server</p></li>
<li><p>In the PyCharm menu, select <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Attach</span><spanclass="pre">to</span><spanclass="pre">Process...</span></code></p></li>
<li><p>From the list, pick the corresponding process id, it should be the <codeclass="docutils literal notranslate"><spanclass="pre">twistd</span></code> process with the <codeclass="docutils literal notranslate"><spanclass="pre">server.py</span></code> parameter (Example: <codeclass="docutils literal notranslate"><spanclass="pre">twistd.exe</span><spanclass="pre">--nodaemon</span><spanclass="pre">--logfile=\<mygame\>\server\logs\server.log</span><spanclass="pre">--python=\<evennia</span><spanclass="pre">repo\>\evennia\server\server.py</span></code>)</p></li>
</ol>
<p>You can attach to the <codeclass="docutils literal notranslate"><spanclass="pre">portal</span></code> process as well, if you want to debug the Evennia launcher
or runner for some reason (or just learn how they work!), see Run Configuration below.</p>
<blockquote>
<div><p>NOTE: Whenever you reload Evennia, the old Server process will die and a new one start. So when you restart you have to detach from the old and then reattach to the new process that was created.</p>
<h3>Run Evennia with a Run/Debug Configuration<aclass="headerlink"href="#run-evennia-with-a-run-debug-configuration"title="Link to this heading">¶</a></h3>
<p>This configuration allows you to launch Evennia from inside PyCharm.
Besides convenience, it also allows suspending and debugging the evennia_launcher or evennia_runner
at points earlier than you could by running them externally and attaching.
In fact by the time the server and/or portal are running the launcher will have exited already.</p>
<sectionid="on-windows">
<h4>On Windows<aclass="headerlink"href="#on-windows"title="Link to this heading">¶</a></h4>
<olclass="arabic simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code></p></li>
<li><p>Click the plus-symbol to add a new configuration and choose Python</p></li>
<li><p>Add the script: <codeclass="docutils literal notranslate"><spanclass="pre">\<yourprojectfolder>\.evenv\Scripts\evennia_launcher.py</span></code> (substitute your virtualenv if it’s not named <codeclass="docutils literal notranslate"><spanclass="pre">evenv</span></code>)</p></li>
<li><p>Ensure the chosen interpreter is your virtualenv</p></li>
<li><p>Set Working directory to your <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code> folder (not your project folder nor evennia)</p></li>
<li><p>You can refer to the PyCharm documentation for general info, but you’ll want to set at least a config name (like “MyMUD start” or similar).</p></li>
</ol>
<p>A dropdown box holding your new configurations should appear next to your PyCharm run button.
Select it start and press the debug icon to begin debugging.</p>
</section>
<sectionid="on-linux">
<h4>On Linux<aclass="headerlink"href="#on-linux"title="Link to this heading">¶</a></h4>
<olclass="arabic simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code></p></li>
<li><p>Click the plus-symbol to add a new configuration and choose Python</p></li>
<li><p>Add the script: <codeclass="docutils literal notranslate"><spanclass="pre">/<yourprojectfolder>/.evenv/bin/twistd</span></code> (substitute your virtualenv if it’s not named <codeclass="docutils literal notranslate"><spanclass="pre">evenv</span></code>)</p></li>
<li><p>Set script parameters to: <codeclass="docutils literal notranslate"><spanclass="pre">--python=/<yourprojectfolder>/.evenv/lib/python3.11/site-packages/evennia/server/server.py</span><spanclass="pre">--logger=evennia.utils.logger.GetServerLogObserver</span><spanclass="pre">--pidfile=/<yourprojectfolder>/<yourgamefolder>/server/server.pid</span><spanclass="pre">--nodaemon</span></code></p></li>
<li><p>Add an environment variable <codeclass="docutils literal notranslate"><spanclass="pre">DJANGO_SETTINGS_MODULE=server.conf.settings</span></code></p></li>
<li><p>Ensure the chosen interpreter is your virtualenv</p></li>
<li><p>Set Working directory to your game folder (not your project folder nor evennia)</p></li>
<li><p>You can refer to the PyCharm documentation for general info, but you’ll want to set at least a config name (like “MyMUD Server” or similar).</p></li>
</ol>
<p>A dropdown box holding your new configurations should appear next to your PyCharm run button.
Select it start and press the debug icon to begin debugging.
Note that this only starts the server process, you can either start the portal manually or set up
the configuration for the portal. The steps are very similar to the ones above.</p>
<olclass="arabic simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code></p></li>
<li><p>Click the plus-symbol to add a new configuration and choose Python</p></li>
<li><p>Add the script: <codeclass="docutils literal notranslate"><spanclass="pre">/<yourprojectfolder>/.evenv/bin/twistd</span></code> (substitute your virtualenv if it’s not named <codeclass="docutils literal notranslate"><spanclass="pre">evenv</span></code>)</p></li>
<li><p>Set script parameters to: <codeclass="docutils literal notranslate"><spanclass="pre">--python=/<yourprojectfolder>/.evenv/lib/python3.11/site-packages/evennia/server/portal/portal.py</span><spanclass="pre">--logger=evennia.utils.logger.GetServerLogObserver</span><spanclass="pre">--pidfile=/<yourprojectfolder>/<yourgamefolder>/server/portal.pid</span><spanclass="pre">--nodaemon</span></code></p></li>
<li><p>Add an environment variable <codeclass="docutils literal notranslate"><spanclass="pre">DJANGO_SETTINGS_MODULE=server.conf.settings</span></code></p></li>
<li><p>Ensure the chosen interpreter is your virtualenv</p></li>
<li><p>Set Working directory to your game folder (not your project folder nor evennia)</p></li>
<li><p>You can refer to the PyCharm documentation for general info, but you’ll want to set at least a config name (like “MyMUD Portal” or similar).</p></li>
</ol>
<p>You should now be able to start both modes and get full debugging.
If you want to go one step further, you can add another config to automatically start both.</p>
<olclass="arabic simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code></p></li>
<li><p>Click the plus-symbol to add a new configuration and choose Compound</p></li>
<li><p>Add your two previous configurations, name it appropriately and press Ok.</p></li>
</ol>
<p>You can now start your game with one click with full debugging active.</p>