-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyCharm.html
More file actions
811 lines (660 loc) · 58.1 KB
/
PyCharm.html
File metadata and controls
811 lines (660 loc) · 58.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
<!DOCTYPE html>
<html lang="en" data-content_root="./" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>PyCharm — MantidProject main documentation</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
</script>
<!--
this give us a css class that will be invisible only if js is disabled
-->
<noscript>
<style>
.pst-js-only { display: none !important; }
</style>
</noscript>
<!-- Loaded before other Sphinx assets -->
<link href="_static/styles/theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link href="_static/styles/pydata-sphinx-theme.css?digest=8878045cc6db502f8baf" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/style.css?v=468c6cff" />
<!-- So that users can add custom icons -->
<script src="_static/scripts/fontawesome.js?digest=8878045cc6db502f8baf"></script>
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf" />
<link rel="preload" as="script" href="_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf" />
<script src="_static/documentation_options.js?v=a8da1a53"></script>
<script src="_static/doctools.js?v=fd6eb6e6"></script>
<script src="_static/sphinx_highlight.js?v=6ffebe34"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'PyCharm';</script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="CLion" href="CLion.html" />
<link rel="prev" title="Visual Studio Build Impact" href="VisualStudioBuildImpact.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en">
<link rel="icon" sizes="32x32" href="_static/images/favicon.ico">
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">
<div id="pst-skip-link" class="skip-link d-print-none"><a href="#main-content">Skip to main content</a></div>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>Back to top</button>
<dialog id="pst-search-dialog">
<form class="bd-search d-flex align-items-center"
action="search.html"
method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search"
class="form-control"
name="q"
placeholder="Search the docs ..."
aria-label="Search the docs ..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"/>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
</dialog>
<div class="pst-async-banner-revealer d-none">
<aside id="bd-header-version-warning" class="d-none d-print-none" aria-label="Version warning"></aside>
</div>
<header class="bd-header navbar navbar-expand-lg bd-navbar d-print-none">
<div class="bd-header__inner bd-page-width">
<button class="pst-navbar-icon sidebar-toggle primary-toggle" aria-label="Site navigation">
<span class="fa-solid fa-bars"></span>
</button>
<div class="col-lg-3 navbar-header-items__start">
<div class="navbar-item">
<a class="navbar-brand logo" href="index.html">
<img src="_static/images/mantid_logo_light.png" class="logo__image only-light" alt="Logo image">
<img src="_static/images/mantid_logo_dark.png" class="logo__image only-dark" alt="Logo image">
</a></div>
</div>
<div class="col-lg-9 navbar-header-items">
<div class="me-auto navbar-header-items__center">
<div class="navbar-item"><ul id="navbar-main-elements" class="navbar-nav">
<li class="nav-item">
<a class="reference internal nav-link" href="https://download.mantidproject.org">Downloads</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org/nightly/tutorials/">Tutorials</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org">User Docs</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://developer.mantidproject.org">Develop</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org/release/">Release notes</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://forum.mantidproject.org/">Forums</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://www.mantidproject.org/contact">Contact Us</a>
</li>
</ul></div>
</div>
<div class="navbar-header-items__end">
<div class="navbar-item navbar-persistent--container">
<button class="btn search-button-field search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
</div>
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item"><ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a class="nav-link" href="https://github.com/mantidproject/mantid" rel="noopener" target="_blank" title="GitHub">
<span><i class="fab fa-github-square"></i></span>
<label class="sr-only">GitHub</label>
</a>
</li>
</ul></div>
</div>
</div>
<div class="navbar-persistent--mobile">
<button class="btn search-button-field search-button__button pst-js-only" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
<span class="search-button__default-text">Search</span>
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
</button>
</div>
<button class="pst-navbar-icon sidebar-toggle secondary-toggle" aria-label="On this page">
<span class="fa-solid fa-outdent"></span>
</button>
</div>
</header>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<dialog id="pst-primary-sidebar-modal"></dialog>
<div id="pst-primary-sidebar" class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
<div class="sidebar-header-items__center">
<div class="navbar-item"><ul id="navbar-main-elements" class="navbar-nav">
<li class="nav-item">
<a class="reference internal nav-link" href="https://download.mantidproject.org">Downloads</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org/nightly/tutorials/">Tutorials</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org">User Docs</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://developer.mantidproject.org">Develop</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://docs.mantidproject.org/release/">Release notes</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://forum.mantidproject.org/">Forums</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="https://www.mantidproject.org/contact">Contact Us</a>
</li>
</ul></div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button pst-js-only" aria-label="Color mode" data-bs-title="Color mode" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light" title="Light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark" title="Dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto" title="System Settings"></i>
</button></div>
<div class="navbar-item"><ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a class="nav-link" href="https://github.com/mantidproject/mantid" rel="noopener" target="_blank" title="GitHub">
<span><i class="fab fa-github-square"></i></span>
<label class="sr-only">GitHub</label>
</a>
</li>
</ul></div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
aria-label="Section Navigation">
<p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p>
<div class="bd-toc-item navbar-nav"></div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
<div class="sidebar-primary-item">
<div id="ethical-ad-placement"
class="flat"
data-ea-publisher="readthedocs"
data-ea-type="readthedocs-sidebar"
data-ea-manual="true">
</div></div>
</div>
</div>
<main id="main-content" class="bd-main" role="main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article d-print-none">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item">
<nav aria-label="Breadcrumb" class="d-print-none">
<ul class="bd-breadcrumbs">
<li class="breadcrumb-item breadcrumb-home">
<a href="index.html" class="nav-link" aria-label="Home">
<i class="fa-solid fa-home"></i>
</a>
</li>
<li class="breadcrumb-item active" aria-current="page"><span class="ellipsis">PyCharm</span></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article">
<section class="tex2jax_ignore mathjax_ignore" id="pycharm">
<span id="pycharm-ref"></span><h1>PyCharm<a class="headerlink" href="#pycharm" title="Link to this heading">#</a></h1>
<section id="selecting-pycharm-versions">
<h2>Selecting PyCharm versions<a class="headerlink" href="#selecting-pycharm-versions" title="Link to this heading">#</a></h2>
<p>There are two versions of PyCharm that are in use in the team, Community and Professional.
The main difference for our workflow is that professional offers support for remote debugging which can help with debugging Python code that is called from C++, such as algorithms called from Python interfaces.</p>
<p>If you haven’t installed PyCharm yet do that now, PyCharm can be installed from <a class="reference external" href="https://jetbrains.com/pycharm/download/">here</a>.</p>
</section>
<section id="setup-python-development-environment-with-conda">
<h2>Setup Python development environment with conda<a class="headerlink" href="#setup-python-development-environment-with-conda" title="Link to this heading">#</a></h2>
<p>The assumption has been made that you have setup and built Mantid already.
If you have not, please do so before hand by following <a class="reference internal" href="GettingStarted/GettingStarted.html"><span class="std std-doc">this guide</span></a>.</p>
<p>At any point in these instructions where <code class="docutils literal notranslate"><span class="pre">DebugWithRelRuntime</span></code> is used (including in file paths),
you can replace it with any other build type such as <code class="docutils literal notranslate"><span class="pre">Debug</span></code> or <code class="docutils literal notranslate"><span class="pre">Release</span></code>.
We use <code class="docutils literal notranslate"><span class="pre">DebugWithRelRuntime</span></code> for conda specific builds to allow debugging due to <code class="docutils literal notranslate"><span class="pre">Debug</span></code> not being functional with the <code class="docutils literal notranslate"><span class="pre">Release</span> <span class="pre">ABIs</span></code>.</p>
<ul class="simple">
<li><p>Open PyCharm</p></li>
<li><p>If no project has been selected already, open the Mantid source code as a project.</p></li>
<li><p>Open the <code class="docutils literal notranslate"><span class="pre">File->Settings</span> <span class="pre">menu</span></code>.</p></li>
<li><p>In the left hand side select the option that is <code class="docutils literal notranslate"><span class="pre">Project:</span> <span class="pre">{SOURCE_CODE_FOLDER_NAME}</span></code> for example <code class="docutils literal notranslate"><span class="pre">Project:</span> <span class="pre">mantid</span></code>.</p></li>
<li><p>Select the <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Interpreter</span></code> option.</p></li>
<li><p>Click <code class="docutils literal notranslate"><span class="pre">Add</span> <span class="pre">Interpreter</span></code> on the top right, then <code class="docutils literal notranslate"><span class="pre">Add</span> <span class="pre">Local</span> <span class="pre">Interpreter...</span></code>.</p></li>
<li><p>From the left side of the window select <code class="docutils literal notranslate"><span class="pre">Conda</span> <span class="pre">Environment</span></code>.</p></li>
<li><p>Add the path to your conda executable, e.g. <code class="docutils literal notranslate"><span class="pre">C:\Users\<username>\AppData\Local\miniforge\Scripts\conda.exe</span></code> and click <code class="docutils literal notranslate"><span class="pre">Load</span> <span class="pre">Environments</span></code>.</p></li>
<li><p>Click the <code class="docutils literal notranslate"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">environment</span></code> radio button and select the <code class="docutils literal notranslate"><span class="pre">mantid-developer</span></code> environment in the drop down list.</p></li>
<li><p>Click OK to close the window.</p></li>
<li><p>Ensure that next to <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Interpreter:</span></code> it says <code class="docutils literal notranslate"><span class="pre">mantid-developer</span></code>.
You will also see a list of the python packages installed in your mantid-developer environment.</p></li>
<li><p>Then click Apply.</p></li>
<li><p>Back on the left side, under <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Interpreter</span></code> there should be an option for <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Structure</span></code>. Select that.</p></li>
<li><p>If you do not build Mantid in the same directory as your source but somewhere else add this as another Content Root, by selecting <code class="docutils literal notranslate"><span class="pre">+</span> <span class="pre">Add</span> <span class="pre">Content</span> <span class="pre">Root</span></code> on the right hand side now.</p></li>
<li><p>In the file tree, select each of the following and mark them as source directories by clicking the <code class="docutils literal notranslate"><span class="pre">Sources</span></code> button while they are selected:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/scripts</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/Framework/PythonInterface</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/qt/applications/workbench</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/qt/widgets</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/qt/python/mantidqt</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">{SOURCE}/qt/python/mantidqtinterfaces</span></code></p></li>
</ul>
</li>
<li><p>In the file tree select your build directory and mark as excluded by clicking the <code class="docutils literal notranslate"><span class="pre">Excluded</span></code> button whilst it’s selected.</p></li>
<li><p>If the <code class="docutils literal notranslate"><span class="pre">.pixi</span></code> directory exists, mark it as excluded.</p></li>
<li><p>On Windows, select the <code class="docutils literal notranslate"><span class="pre">{BUILD}/bin/DebugWithRelRuntime</span></code> directory and mark as source by clicking the <code class="docutils literal notranslate"><span class="pre">Sources</span></code> button whilst it’s selected.</p></li>
<li><p>On Linux or MacOS, select your <code class="docutils literal notranslate"><span class="pre">{BUILD}/bin</span></code> directory and mark as source by clicking the <code class="docutils literal notranslate"><span class="pre">Sources</span></code> button whilst it’s selected.</p></li>
<li><p>Click Apply, and then OK to close the window.</p></li>
</ul>
</section>
<section id="debug-python-in-workbench">
<span id="debug-workbench-in-pycharm-ref"></span><h2>Debug Python in Workbench<a class="headerlink" href="#debug-python-in-workbench" title="Link to this heading">#</a></h2>
<p>Now that your Python development environment has been setup we can setup the debugging using Workbench.</p>
<ul class="simple">
<li><p>With an open project in Pycharm, open the Play configuration menu by Opening <code class="docutils literal notranslate"><span class="pre">Run->Edit</span> <span class="pre">Configurations...</span></code>.</p></li>
<li><p>Click the <code class="docutils literal notranslate"><span class="pre">+</span></code> icon top left</p></li>
<li><p>Select Python</p></li>
<li><p>Name it something to do with <code class="docutils literal notranslate"><span class="pre">Workbench</span></code></p></li>
<li><p>Click the down arrow next to <code class="docutils literal notranslate"><span class="pre">Script</span> <span class="pre">path:</span></code> and change the selection to <code class="docutils literal notranslate"><span class="pre">Module</span> <span class="pre">name</span></code>. Set the <code class="docutils literal notranslate"><span class="pre">Module</span> <span class="pre">name</span></code> to <code class="docutils literal notranslate"><span class="pre">workbench</span></code>.</p></li>
<li><p>In the <code class="docutils literal notranslate"><span class="pre">Parameters</span></code> box add <code class="docutils literal notranslate"><span class="pre">--single-process</span></code> so that the multiprocess startup is disabled and breakpoints can be attached to the primary process. See the <a class="reference internal" href="Workbench/RunningWorkbench.html#runningworkbench"><span class="std std-ref">Running Workbench</span></a> documentation for more information.</p></li>
<li><p>In the <code class="docutils literal notranslate"><span class="pre">Working</span> <span class="pre">directory:</span></code> box, on Linux/MacOS enter the <code class="docutils literal notranslate"><span class="pre">{BUILD}/bin</span></code> directory, on Windows enter <code class="docutils literal notranslate"><span class="pre">{BUILD}/bin/DebugWithRelRuntime</span></code> directory.</p></li>
<li><p>Ensure the <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Interpreter:</span></code> box is set to use your <code class="docutils literal notranslate"><span class="pre">(mantid-developer)</span></code> conda environment.</p></li>
<li><p>Click OK to save and exit the window.</p></li>
<li><p>You can now click the green play button in the top right of the window to create a Workbench instance from pycharm.</p></li>
<li><p>Alternatively you can click the green bug next to the green play button to start a debug session.</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>On Windows, you may see the following error when launching workbench in
debug mode:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>incompatible<span class="w"> </span>copy<span class="w"> </span>of<span class="w"> </span>pydevd<span class="w"> </span>already<span class="w"> </span>imported:
C:<span class="se">\P</span>rogram<span class="w"> </span>Files<span class="se">\J</span>etBrains<span class="se">\P</span>yCharm<span class="w"> </span>Community<span class="w"> </span>Edition<span class="w"> </span><span class="m">2023</span>.1.2<span class="se">\p</span>lugins<span class="se">\p</span>ython-ce<span class="se">\h</span>elpers<span class="se">\p</span>ydev<span class="se">\_</span>pydev_bundle<span class="se">\_</span>_init__.py
C:<span class="se">\P</span>rogram<span class="w"> </span>Files<span class="se">\J</span>etBrains<span class="se">\P</span>yCharm<span class="w"> </span>Community<span class="w"> </span>Edition<span class="w"> </span><span class="m">2023</span>.1.2<span class="se">\p</span>lugins<span class="se">\p</span>ython-ce<span class="se">\h</span>elpers<span class="se">\p</span>ydev<span class="se">\_</span>pydev_bundle<span class="se">\_</span>pydev_calltip_util.py
...
</pre></div>
</div>
</div>
<p>To resolve the error, remove <strong>only</strong> the debugpy package from your conda environment with</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>conda<span class="w"> </span>remove<span class="w"> </span>debugpy<span class="w"> </span>--force
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">--force</span></code> argument tells conda to remove the single package only, ignoring the packages that depend on debugpy.
Note that the Mamba implementation of <code class="docutils literal notranslate"><span class="pre">remove</span> <span class="pre">--force</span></code> did not skip dependency checking until version 1.5.2 (October 2023).
If your version of Mamba is older than this, use the conda command.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>
```{include} macos-opengl-version-warning.md
</pre></div>
</div>
</section>
<section id="debug-python-in-unit-tests">
<h2>Debug Python in unit tests<a class="headerlink" href="#debug-python-in-unit-tests" title="Link to this heading">#</a></h2>
<p>This section assumes you have followed all previous instructions for debugging Python in workbench</p>
<p>There are 2 main ways to debug Python unit tests using the Unittests Python module.</p>
<ol class="arabic simple">
<li><p>Navigate to the test you want to run in PyCharm, on the left side of the file in the margin, just to the right of the line numbers there should be a green play button, click that and it will let you start a debug or normal run of the tests.</p></li>
<li><p>A little more involved, but is easier to expand and test many things at once.</p>
<ul class="simple">
<li><p>Same as when creating the Workbench debug session. Open the configuration menu by navigating to <code class="docutils literal notranslate"><span class="pre">Run->Edit</span> <span class="pre">Configurations...</span></code></p></li>
<li><p>Click the <code class="docutils literal notranslate"><span class="pre">+</span></code> icon top left</p></li>
<li><p>Select Unittests</p></li>
<li><p>Give an appropriate name for the section of code you will be testing</p></li>
<li><p>You have 3 options, enter the module name, script path or custom.</p>
<ul>
<li><p>Module name for testing workbench project recovery tests looks like this <code class="docutils literal notranslate"><span class="pre">workbench.projectrecovery</span></code>, this runs all of the tests in the project recovery section. This is very useful for testing all of a specific section of the code base, without running it in a terminal.</p></li>
<li><p>Script path is very similar instead of passing a module name, you just give a filepath such as <code class="docutils literal notranslate"><span class="pre">{SOURCE}/qt/applications/workbench/workbench/projectrecovery</span></code> this achieves exactly the same as the previous step.</p></li>
<li><p>Custom is for passing custom arguments to the Unittests executable such as <a class="reference external" href="https://docs.python.org/3/library/unittest.html#command-line-interface">these</a></p></li>
</ul>
</li>
</ul>
</li>
</ol>
</section>
<section id="debug-python-in-system-tests-remote-debugging">
<h2>Debug Python in system tests/remote debugging<a class="headerlink" href="#debug-python-in-system-tests-remote-debugging" title="Link to this heading">#</a></h2>
<p>This functionality is useful for debugging Python code that is spawned in separate threads, such as Python algorithms called from C++ and system tests.</p>
<p>A PyCharm Professional license is required to use the Remote Debugging feature.</p>
<p>This section assumes you have followed all previous instructions for debugging Python in workbench and unit tests.</p>
<ul>
<li><p>Like the Unit tests and workbench we need to add it as a configuration, open the configuration menu by navigating to <code class="docutils literal notranslate"><span class="pre">Run->Edit</span> <span class="pre">Configurations...</span></code></p></li>
<li><p>Click the <code class="docutils literal notranslate"><span class="pre">+</span></code> icon top left</p></li>
<li><p>Select <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Debug</span> <span class="pre">Server</span></code></p></li>
<li><p>Give an appropriate name for remote debugging such as <code class="docutils literal notranslate"><span class="pre">Remote</span> <span class="pre">Debugging</span></code></p></li>
<li><p>Copy the snippet of code that consists of <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">pydevd-pycharm</span></code></p></li>
<li><p>Close the configuration window</p></li>
<li><p>Open Terminal at the bottom of the PyCharm window</p></li>
<li><p>Paste the snippet of code and hit enter, this will install the remote debugger for PyCharm to use.</p></li>
<li><p>Once installed, re-open the configuration menu by navigating to <code class="docutils literal notranslate"><span class="pre">Run->Edit</span> <span class="pre">Configurations...</span></code></p></li>
<li><p>Ensure that the previously created <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Debug</span> <span class="pre">Server</span></code> is selected in the left hand side tree selection.</p></li>
<li><p>Ensure that you set the port box to something that isn’t 0 and isn’t in use by your system at present such as <code class="docutils literal notranslate"><span class="pre">8080</span></code>.</p></li>
<li><p>Copy the snippet of Python code that looks like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">pydevd_pycharm</span>
<span class="n">pydevd_pycharm</span><span class="o">.</span><span class="n">settrace</span><span class="p">(</span><span class="s2">"localhost"</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">8080</span><span class="p">,</span> <span class="n">stdoutToServer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">stderrToServer</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>Paste this code where you want to start debugging from, this will act like a breakpoint during normal debugging.</p></li>
<li><p>Click the drop down menu next to the play icon in the top right. Select the <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Debug</span> <span class="pre">Server</span></code> you configured, then click the debug next to the play icon.</p></li>
<li><p>Run the python code that you want to debug, for example run the system tests, and it will pause execution on where you pasted your remote debug code earlier.</p></li>
<li><p>Any new breakpoints can be added like normal but they must come after the remote code snippet pasted earlier.</p></li>
</ul>
</section>
</section>
<section class="tex2jax_ignore mathjax_ignore" id="legacy-and-not-maintained-past-this-point-only-use-if-explicitly-not-using-conda">
<h1>Legacy and not maintained past this point (Only use if explicitly not using conda)<a class="headerlink" href="#legacy-and-not-maintained-past-this-point-only-use-if-explicitly-not-using-conda" title="Link to this heading">#</a></h1>
<section id="setting-up-pycharm-on-windows">
<h2>Setting up PyCharm on Windows<a class="headerlink" href="#setting-up-pycharm-on-windows" title="Link to this heading">#</a></h2>
<ol class="arabic">
<li><p>Once PyCharm is open, set up the project. Go to <code class="docutils literal notranslate"><span class="pre">File->Open</span></code> and select the root directory in which both your source and build directories reside.</p>
<p>Go to <code class="docutils literal notranslate"><span class="pre">File->Settings</span></code>, then under <code class="docutils literal notranslate"><span class="pre">Project</span></code> you will set two sub-menus <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Interpreter</span></code> and <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Structure</span></code>.
The interpreter defines the Python executable that will be used to run your code, and the structure menu allows you to decide which folders within the project to include and index.</p>
</li>
<li><p>In the <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Interpreter</span></code> sub menu, at the top select the options button and click <code class="docutils literal notranslate"><span class="pre">Add...</span></code>, a new window should appear titled “Add Python Interpreter”.
In the menu on the left, if you are using conda select “Conda Environment”, if you haven’t set up conda follow the Getting Started guidance for it, select existing environment and if not present already put in the path to your Python interpreter, and your conda executable.
Alternatively select “System Interpreter” (a version of Python with all the correct variables set already exists within Mantid, if you are not using Conda).
Click on the <code class="docutils literal notranslate"><span class="pre">...</span></code> to open a file browser, and navigate to;</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/external/src/ThirdParty/lib/Python3.8/Python.exe
</pre></div>
</div>
<p>This is the interpreter, so select “Ok” and apply the changes.
This should bring up a list of all the packages associated to the interpreter.
There should be many packages, however you should not see PyQt (but instead QtPy).</p>
</li>
<li><p>In the <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Structure</span></code> sub menu you should see your root directory with the source/build directories both visible (if not, add them).
The folder structure should be present in the centre of the window allowing you to mark folders orange (excluded) or blue (source).
Source directories will be searched for Python code.</p>
<p>Within the source directory add the following to your sources:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/scripts
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/Framework/PythonInterface
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/applications/workbench
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/widgets
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/Python
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/external/src/ThirdParty/lib
</pre></div>
</div>
<p>If you are writing scripts in any other directories, you can also mark them as sources.
This helps PyCharm give better auto-complete and import suggestions during development.</p>
<p>Additionally, in the Mantid build directory add the following as source folders:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Build<span class="w"> </span>Directory>/bin/Debug
</pre></div>
</div>
<p>here we are setting up PyCharm for the Debug build, you would use <code class="docutils literal notranslate"><span class="pre">/bin/Release</span></code> instead if you are building mantid in release mode.</p>
</li>
<li><p>The environment needs to be set up before running the configuration.
Follow the instructions below to use either the EnvFile plugin (recommended) or manual path setup.</p></li>
</ol>
<p>NOTE : In some cases, imports in the code will still be highlighted red when they come from folders within the <code class="docutils literal notranslate"><span class="pre">script/</span></code> folder, or from other folders entirely.
To fix this simply add the relevant folder that contains the module you are importing in the same fashion as step 3 above.</p>
</section>
<section id="running-files-in-the-debugger-with-envfile-extension">
<span id="pycharm-debugging-env-file"></span><h2>Running Files in the Debugger with EnvFile extension<a class="headerlink" href="#running-files-in-the-debugger-with-envfile-extension" title="Link to this heading">#</a></h2>
<p>Do not run files in the debugger with EnvFile extension with conda, as conda does this job for you.</p>
<p>Running Python code from within PyCharm which depends on the Python API, or PyQt for example requires one extra step. Because the source root labelling from the previous section only affects PyCharm searching and not the run configuration, before running the file we must set up the run configuration correctly.</p>
<ol class="arabic simple" start="4">
<li><p>Install the EnvFile plugin by Borys Pierov. The plugin can be installed in multiple ways:</p>
<ol class="arabic simple">
<li><p>Open Settings(CTRL + SHIFT + S), to go Plugins and search for <code class="docutils literal notranslate"><span class="pre">EnvFile</span></code>. Install and restart PyCharm.</p></li>
<li><p>Go to the plugin’s <a class="reference external" href="https://plugins.jetbrains.com/plugin/7861-envfile">webpage</a>, download and install it.</p></li>
</ol>
</li>
<li><p>To edit the configurations go to Run->Run… and select Edit Configurations. Notice that there is now a <code class="docutils literal notranslate"><span class="pre">EnvFile</span></code> tab under the configuration’s name.</p>
<ul class="simple">
<li><p>Note that you have to do that for each configuration, or you can change the template configuration, and all configuration that use that template will have the EnvFile setup.</p></li>
</ul>
</li>
<li><p>Open the <code class="docutils literal notranslate"><span class="pre">EnvFile</span></code> tab, check <code class="docutils literal notranslate"><span class="pre">Enable</span> <span class="pre">EnvFile</span></code> and <code class="docutils literal notranslate"><span class="pre">Substitute</span> <span class="pre">Environmental</span> <span class="pre">Variables</span> <span class="pre">(...)</span></code> - this allows setting up the third-party paths dynamically.</p></li>
<li><p>Click the <code class="docutils literal notranslate"><span class="pre">+</span></code> (plus) on the right side, select the <code class="docutils literal notranslate"><span class="pre">pycharm.env</span></code> file in the root of the <strong>build</strong> directory.</p></li>
</ol>
<p>For running the Workbench continue onto <a class="reference internal" href="Workbench/index.html#workbenchindex"><span class="std std-ref">Workbench</span></a>, and follow the instructions to set up the <em>Script Path</em> and <em>Working Directory</em>.</p>
<p>Advantages of this approach:</p>
<ul class="simple">
<li><p>You can have multiple instances of PyCharm running with environment configuration for separate repositories.
This is otherwise not possible, as all PyCharm instances seem to share a parent process and environment.
(as is the case of 11/01/2019, it might change in the future)</p></li>
<li><p>This makes possible switching projects for multiple repositories via the File > Open Recent … menu, as when the new project is opened its environment won’t be poluted with environment variables from the last one.</p></li>
<li><p>This can cause errors when the external dependencies aren’t quite the same between all the repositories, as some packages might be missing, or be different versions.</p></li>
</ul>
<p>Disadvantages:</p>
<ul class="simple">
<li><p>Additional setup for each configuration necessary.
Thankfully, if the template is edited to have the correct <code class="docutils literal notranslate"><span class="pre">EnvFile</span></code> setup, all copies of it will have it too.
Copying an already existing configuration also copies the <code class="docutils literal notranslate"><span class="pre">EnvFile</span></code> setup.</p></li>
</ul>
</section>
<section id="running-files-in-the-debugger-without-envfile-extension">
<h2>Running Files in the Debugger without EnvFile extension<a class="headerlink" href="#running-files-in-the-debugger-without-envfile-extension" title="Link to this heading">#</a></h2>
<p>This can be done in two ways:</p>
<ul>
<li><p>Open PyCharm using <code class="docutils literal notranslate"><span class="pre">pycharm.bat</span></code> which can be found in the build directory (this sets some additional environment variables compared with simply opening PyCharm directly).</p>
<ul class="simple">
<li><p>This is preferred if you only have 1 repository with which PyCharm is used.
If you need to use PyCharm on multiple repositories, it is recommended that you use the EnvFile extension.</p></li>
</ul>
</li>
<li><p>To edit the configurations go to <code class="docutils literal notranslate"><span class="pre">Run->Run...</span></code> and select <code class="docutils literal notranslate"><span class="pre">Edit</span> <span class="pre">Configurations</span></code>.
This should open up a sub window.
Hit the green <code class="docutils literal notranslate"><span class="pre">+</span></code> in the top left to create a new configuration and name it.
In order to tell PyCharm where to look for Python modules and libraries we need to add some folders to the <code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment variable.
Click on the <code class="docutils literal notranslate"><span class="pre">...</span></code> next to the <em>Environment Variables</em> box, and hit the <code class="docutils literal notranslate"><span class="pre">+</span></code> icon.
In the Name column enter “PATH”, in the value column enter the following;</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Build<span class="w"> </span>Directory><span class="se">\b</span>in<span class="se">\D</span>ebug<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\b</span>in<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\b</span>in<span class="se">\m</span>ingw<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\l</span>ib<span class="se">\P</span>ython3.8<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\l</span>ib<span class="se">\q</span>t5<span class="se">\p</span>lugins<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\l</span>ib<span class="se">\q</span>t5<span class="se">\b</span>in<span class="p">;</span>
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory><span class="se">\e</span>xternal<span class="se">\s</span>rc<span class="se">\T</span>hirdParty<span class="se">\l</span>ib<span class="se">\q</span>t5<span class="se">\l</span>ib<span class="p">;</span>
%PATH%
</pre></div>
</div>
</li>
</ul>
<p>The semi-colon delimited list of paths should end in <code class="docutils literal notranslate"><span class="pre">;%PATH%</span></code> so that we prepend to the existing list of paths rather than overwriting them.</p>
<p>You should now be able to run and debug the scripts using the newly created configuration, by adding the full path of the file in the <code class="docutils literal notranslate"><span class="pre">Script</span> <span class="pre">path</span></code> box at the top of the configuration window.</p>
<p>As an example, create a new file in <code class="docutils literal notranslate"><span class="pre"><Mantid</span> <span class="pre">Source</span> <span class="pre">Directory>/scripts/</span></code> called <code class="docutils literal notranslate"><span class="pre">test.py</span></code>. Copy into it the Python code below.</p>
</section>
<section id="testing-using-pyqt">
<h2>Testing using PyQt<a class="headerlink" href="#testing-using-pyqt" title="Link to this heading">#</a></h2>
<p>To test that the above instructions have worked, you can simply create a new Python file with the following content (for PyQt5)</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Check that PyQt imports</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">qtpy</span><span class="w"> </span><span class="kn">import</span> <span class="n">QtCore</span><span class="p">,</span> <span class="n">QtGui</span><span class="p">,</span> <span class="n">QtWidgets</span>
<span class="c1"># Check that the Mantid Python API imports</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">mantid.simpleapi</span>
<span class="k">class</span><span class="w"> </span><span class="nc">DummyView</span><span class="p">(</span><span class="n">QtWidgets</span><span class="o">.</span><span class="n">QWidget</span><span class="p">):</span>
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">DummyView</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">grid</span> <span class="o">=</span> <span class="n">QtWidgets</span><span class="o">.</span><span class="n">QGridLayout</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="n">btn</span> <span class="o">=</span> <span class="n">QtWidgets</span><span class="o">.</span><span class="n">QPushButton</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="n">btn</span><span class="p">)</span>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">sys</span>
<span class="n">app</span> <span class="o">=</span> <span class="n">QtWidgets</span><span class="o">.</span><span class="n">QApplication</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
<span class="n">ui</span> <span class="o">=</span> <span class="n">DummyView</span><span class="p">(</span><span class="s2">"Hello"</span><span class="p">)</span>
<span class="n">ui</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">exec_</span><span class="p">())</span>
</pre></div>
</div>
</section>
<section id="local-debugging-of-unit-tests-with-pycharm">
<h2>Local Debugging of Unit Tests with PyCharm<a class="headerlink" href="#local-debugging-of-unit-tests-with-pycharm" title="Link to this heading">#</a></h2>
<p>This <strong>does not</strong> require a PyCharm Professional license for debugging, but requires additional setup for running unit tests.</p>
<ol class="arabic simple">
<li><p>Go to your Run/Debug Configurations.</p></li>
<li><p>Open Templates > Python tests > Unittests configuration.</p></li>
<li><p>Set the working directory to <code class="docutils literal notranslate"><span class="pre"><Mantid</span> <span class="pre">Build</span> <span class="pre">Dir>/bin/Debug</span></code>, for a Debug build, or <code class="docutils literal notranslate"><span class="pre"><Mantid</span> <span class="pre">Build</span> <span class="pre">Dir>/bin/Release</span></code> for a Release build.</p></li>
<li><p>Add the EnvFile to the Unittests configuration, instructions in <a class="reference internal" href="#pycharm-debugging-env-file"><span class="std std-ref">Pycharm Debugging Env File</span></a>.</p></li>
<li><p>You should now be able to click the Run/Debug icons next to each unit test method or class to run/debug them.</p></li>
</ol>
</section>
<section id="setting-up-pycharm-on-linux">
<h2>Setting up PyCharm on Linux<a class="headerlink" href="#setting-up-pycharm-on-linux" title="Link to this heading">#</a></h2>
<ol class="arabic">
<li><p>Use the native Python interpreter (<code class="docutils literal notranslate"><span class="pre">/usr/bin/Python3</span></code>) rather than from <code class="docutils literal notranslate"><span class="pre"><Mantid</span> <span class="pre">Source</span> <span class="pre">Directory>/external/src/ThirdParty/lib/Python3.8/Python.exe</span></code></p></li>
<li><p>In the <code class="docutils literal notranslate"><span class="pre">Project</span> <span class="pre">Structure</span></code> sub menu you should see your root directory with the source/build directories both visible (if not, add them).
The folder structure should be present in the centre of the window allowing you to mark folders orange (excluded) or blue (source).
Source directories will be searched for Python code.</p>
<p>Within the source directory add the following to your sources:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/scripts
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/Framework/PythonInterface
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/applications/workbench
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/widgets
<Mantid<span class="w"> </span>Source<span class="w"> </span>Directory>/qt/Python
</pre></div>
</div>
<p>If you are writing scripts in any other directories, you can also mark them as sources. This helps PyCharm give better auto-complete and import suggestions during development.</p>
<p>Additionally, in the Mantid build directory add the following as source folders:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><Mantid<span class="w"> </span>Build<span class="w"> </span>Directory>/bin/
</pre></div>
</div>
<p>It is recommended that you add the whole build folder to <code class="docutils literal notranslate"><span class="pre">excluded</span></code>.
This will not interfere with the <code class="docutils literal notranslate"><span class="pre">bin</span></code> directory, inside the build, being used as a source folder.
It will just limit the scope that PyCharm searches for files, classes, etc.</p>
</li>
<li><p>Go to Run->Run… and select Edit Configurations. Go to Templates> Python. Make <code class="docutils literal notranslate"><span class="pre"><Mantid</span> <span class="pre">Build</span> <span class="pre">Directory>/bin;</span></code> the <code class="docutils literal notranslate"><span class="pre">Working</span> <span class="pre">Directory</span></code>. This will then be used for all Python configurations you make.</p></li>
</ol>
</section>
<section id="useful-plugins">
<h2>Useful Plugins<a class="headerlink" href="#useful-plugins" title="Link to this heading">#</a></h2>
<p>You can install non-default plugins by pressing <code class="docutils literal notranslate"><span class="pre">Ctrl+Alt+S</span></code> to open the <strong>Settings/Preferences</strong> dialog and then going to <strong>Plugins</strong>.
From here you can manage plugins, or add new ones by clicking <strong>Browse repositories</strong>.</p>
<p>The following non-default plugins are things our team has found useful for Mantid development:</p>
<ul class="simple">
<li><p><strong>Markdown support</strong> - Side by side rendering of markdown documents such as<code class="docutils literal notranslate"><span class="pre">.md</span></code> , <code class="docutils literal notranslate"><span class="pre">.rst</span></code> (requires <a class="reference external" href="https://graphviz.gitlab.io/download/">Graphviz</a> to show graphs in preview)</p></li>
<li><p><strong>dotplugin</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">DOT</span></code></p></li>
<li><p><strong>BashSupport</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">BASH</span></code> scripts</p></li>
<li><p><strong>CMD Support</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">.BAT</span></code> ~scripts</p></li>
</ul>
<p>Please add to this list if you find a useful plugin of your own</p>
</section>
<section id="remote-development">
<h2>Remote Development<a class="headerlink" href="#remote-development" title="Link to this heading">#</a></h2>
<p>Note: Requires PyCharm Professional.</p>
<p>PyCharm supports deployment and syncronisation of written code to a remote server via SSH.</p>
<p>Open a local copy of the project and then follow the guides here for <a class="reference external" href="https://www.jetbrains.com/help/pycharm/configuring-remote-interpreters-via-ssh.html">configuring the remote interpreter</a> and <a class="reference external" href="https://www.jetbrains.com/help/pycharm/creating-a-remote-server-configuration.html">creating a deployment configuration</a>.</p>
</section>
</section>
</article>
<footer class="prev-next-footer d-print-none">
<div class="prev-next-area">
<a class="left-prev"
href="VisualStudioBuildImpact.html"
title="previous page">
<i class="fa-solid fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Visual Studio Build Impact</p>
</div>
</a>
<a class="right-next"
href="CLion.html"
title="next page">
<div class="prev-next-info">
<p class="prev-next-subtitle">next</p>
<p class="prev-next-title">CLion</p>
</div>
<i class="fa-solid fa-angle-right"></i>
</a>
</div>
</footer>
</div>
<dialog id="pst-secondary-sidebar-modal"></dialog>
<div id="pst-secondary-sidebar" class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">
<div class="sidebar-secondary-item">
<div
id="pst-page-navigation-heading-2"
class="page-toc tocsection onthispage">
<i class="fa-solid fa-list"></i> On this page
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#">PyCharm</a><ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#selecting-pycharm-versions">Selecting PyCharm versions</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#setup-python-development-environment-with-conda">Setup Python development environment with conda</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#debug-python-in-workbench">Debug Python in Workbench</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#debug-python-in-unit-tests">Debug Python in unit tests</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#debug-python-in-system-tests-remote-debugging">Debug Python in system tests/remote debugging</a></li>
</ul>
</li>
<li class="toc-h1 nav-item toc-entry"><a class="reference internal nav-link" href="#legacy-and-not-maintained-past-this-point-only-use-if-explicitly-not-using-conda">Legacy and not maintained past this point (Only use if explicitly not using conda)</a><ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#setting-up-pycharm-on-windows">Setting up PyCharm on Windows</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#running-files-in-the-debugger-with-envfile-extension">Running Files in the Debugger with EnvFile extension</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#running-files-in-the-debugger-without-envfile-extension">Running Files in the Debugger without EnvFile extension</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#testing-using-pyqt">Testing using PyQt</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#local-debugging-of-unit-tests-with-pycharm">Local Debugging of Unit Tests with PyCharm</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#setting-up-pycharm-on-linux">Setting up PyCharm on Linux</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#useful-plugins">Useful Plugins</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#remote-development">Remote Development</a></li>
</ul>
</li>
</ul>
</nav></div>
<div class="sidebar-secondary-item">
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/PyCharm.md.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div></div>
</div></div>
</div>
<footer class="bd-footer-content">
</footer>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script defer src="_static/scripts/bootstrap.js?digest=8878045cc6db502f8baf"></script>
<script defer src="_static/scripts/pydata-sphinx-theme.js?digest=8878045cc6db502f8baf"></script>
<footer class="bd-footer">
<div class="bd-footer__inner bd-page-width">
<div class="footer-items__start">
<div class="footer-item">
<p class="copyright">
© Copyright 2007-2026, Mantid.
<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 9.1.0.
<br/>
</p>
</div>
</div>
<div class="footer-items__end">
<div class="footer-item">
<p class="theme-version">
<!-- # L10n: Setting the PST URL as an argument as this does not need to be localized -->
Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> 0.16.1.
</p></div>
</div>
</div>
</footer>
</body>
</html>