-
Notifications
You must be signed in to change notification settings - Fork 0
/
GettingStartedWithPyCharm.html
319 lines (280 loc) · 30.3 KB
/
GettingStartedWithPyCharm.html
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getting Started with PyCharm</title>
<link rel="stylesheet" href="_static/bootstrap-sphinx.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="_static/custom.css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="VSCode" href="VSCode.html" />
<link rel="prev" title="Visual Studio Build Impact" href="VisualStudioBuildImpact.html" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-59110517-1', 'auto');
ga('send', 'pageview');
</script>
</head><body>
<div id="navbar" class="navbar navbar-default ">
<div class="container">
<div class="navbar-header">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.mantidproject.org"><img src="_static/Mantid_Logo_Transparent.png">
</a>
<span class="navbar-text navbar-version pull-left"><b>master</b></span>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<li class="divider-vertical"></li>
<li><a href="index.html">Home</a></li>
<li><a href="http://download.mantidproject.org">Download</a></li>
<li><a href="http://www.mantidproject.org">Wiki</a></li>
<li><a href="http://docs.mantidproject.org">User Documentation</a></li>
<li><a href="http://www.mantidproject.org/Contact">Contact Us</a></li>
</ul>
<form class="navbar-form navbar-right" action="search.html" method="get">
<div class="form-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
</div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="body col-md-12 content" role="main">
<div class="section" id="getting-started-with-pycharm">
<span id="gettingstartedwithpycharm"></span><h1>Getting Started with PyCharm<a class="headerlink" href="#getting-started-with-pycharm" title="Permalink to this headline">¶</a></h1>
<p>PyCharm can be installed from <a class="reference external" href="https://jetbrains.com/pycharm/download/">here</a>.</p>
<p>This tutorial assumes you are familiar with the process of building Mantid (with separate source and build directories inside a root directory), and that you have built a working version. If you are unclear about this see <a class="reference internal" href="GettingStarted.html#gettingstarted"><span class="std std-ref">here</span></a>.</p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#setting-up-pycharm-on-windows" id="id2">Setting up PyCharm on Windows</a></li>
<li><a class="reference internal" href="#running-files-in-the-debugger-with-envfile-extension" id="id3">Running Files in the Debugger with EnvFile extension</a></li>
<li><a class="reference internal" href="#running-files-in-the-debugger-without-envfile-extension" id="id4">Running Files in the Debugger without EnvFile extension</a></li>
<li><a class="reference internal" href="#testing-using-pyqt" id="id5">Testing using PyQt</a></li>
<li><a class="reference internal" href="#local-debugging-of-unit-tests-with-pycharm" id="id6">Local Debugging of Unit Tests with PyCharm</a></li>
<li><a class="reference internal" href="#remote-debugging-of-unit-tests-with-pycharm" id="id7">Remote Debugging of Unit Tests with PyCharm</a></li>
<li><a class="reference internal" href="#setting-up-pycharm-on-linux" id="id8">Setting up PyCharm on Linux</a></li>
<li><a class="reference internal" href="#useful-plugins" id="id9">Useful Plugins</a></li>
</ul>
</div>
<div class="section" id="setting-up-pycharm-on-windows">
<span id="id1"></span><h2><a class="toc-backref" href="#id2">Setting up PyCharm on Windows</a><a class="headerlink" href="#setting-up-pycharm-on-windows" title="Permalink to this headline">¶</a></h2>
<ol class="arabic">
<li><p class="first">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 class="first">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, select “System Interpreter” (a version of Python with all the correct variables set already exists within Mantid). 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><Mantid Source Directory>/external/src/ThirdParty/lib/python2.7/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 class="first">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><Mantid Source Directory>/scripts
<Mantid Source Directory>/Framework/PythonInterface
<Mantid Source Directory>/qt/applications/workbench
<Mantid Source Directory>/qt/widgets
<Mantid Source Directory>/qt/python
<Mantid Source 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><Mantid Build 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 class="first">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>
</div>
<div class="section" id="running-files-in-the-debugger-with-envfile-extension">
<span id="running-file-debug-with-envfile-extension"></span><h2><a class="toc-backref" href="#id3">Running Files in the Debugger with EnvFile extension</a><a class="headerlink" href="#running-files-in-the-debugger-with-envfile-extension" title="Permalink to this headline">¶</a></h2>
<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>Install the EnvFile plugin by Borys Pierov. The plugin can be installed in multiple ways:<ol class="loweralpha">
<li>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.</li>
<li>Go to the plugin’s <a class="reference external" href="https://plugins.jetbrains.com/plugin/7861-envfile">webpage</a>, download and install it.</li>
</ol>
</li>
<li>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.
- 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.</li>
<li>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.</li>
<li>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.</li>
</ol>
<p>For running the Workbench continue onto <a class="reference external" href="https://docs.mantidproject.org/nightly/workbench/index.html#workbench" title="(in MantidProject v5.0)"><span>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>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)</li>
<li>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.<ul>
<li>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.</li>
</ul>
</li>
</ul>
<p>Disadvantages:</p>
<ul class="simple">
<li>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.</li>
</ul>
</div>
<div class="section" id="running-files-in-the-debugger-without-envfile-extension">
<h2><a class="toc-backref" href="#id4">Running Files in the Debugger without EnvFile extension</a><a class="headerlink" href="#running-files-in-the-debugger-without-envfile-extension" title="Permalink to this headline">¶</a></h2>
<p>This can be done in two ways:</p>
<ul>
<li><p class="first">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>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.</li>
</ul>
</li>
<li><p class="first">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>
<blockquote>
<div><div class="highlight-sh notranslate"><div class="highlight"><pre><Mantid Build Directory><span class="se">\b</span>in<span class="se">\D</span>ebug<span class="p">;</span>
<Mantid Source 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 Source 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 Source 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>ython2.7<span class="p">;</span>
<Mantid Source 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 Source 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>t4<span class="se">\b</span>in<span class="p">;</span>
<Mantid Source 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 Source 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>t4<span class="se">\l</span>ib<span class="p">;</span>
<Mantid Source 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>
</div></blockquote>
</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>
</div>
<div class="section" id="testing-using-pyqt">
<h2><a class="toc-backref" href="#id5">Testing using PyQt</a><a class="headerlink" href="#testing-using-pyqt" title="Permalink to this headline">¶</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="code python highlight-default notranslate"><div class="highlight"><pre><span class="c1"># Check that PyQt imports</span>
<span class="kn">from</span> <span class="nn">qtpy</span> <span class="k">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="nn">mantid.simpleapi</span>
<span class="k">class</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="nf">__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="n">__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="n">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
<span class="kn">import</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>
</div>
<div class="section" id="local-debugging-of-unit-tests-with-pycharm">
<h2><a class="toc-backref" href="#id6">Local Debugging of Unit Tests with PyCharm</a><a class="headerlink" href="#local-debugging-of-unit-tests-with-pycharm" title="Permalink to this headline">¶</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>Go to your Run/Debug Configurations.</li>
<li>Open Templates > Python tests > Unittests configuration.</li>
<li>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.</li>
<li>Add the EnvFile to the Unittests configuration, instructions in <a class="reference internal" href="#running-file-debug-with-envfile-extension"><span class="std std-ref">Running Files in the Debugger with EnvFile extension</span></a>.</li>
<li>You should now be able to click the Run/Debug icons next to each unit test method or class to run/debug them.</li>
</ol>
</div>
<div class="section" id="remote-debugging-of-unit-tests-with-pycharm">
<h2><a class="toc-backref" href="#id7">Remote Debugging of Unit Tests with PyCharm</a><a class="headerlink" href="#remote-debugging-of-unit-tests-with-pycharm" title="Permalink to this headline">¶</a></h2>
<p>This requires a PyCharm Professional license for the Remote Debugging feature.</p>
<p>This approach can be used to debug unit tests. However, as the required package <code class="docutils literal notranslate"><span class="pre">pydevd</span></code> is not shipped with Mantid, we need to manually add it at runtime. This can be done by appending a directory that contains the installed <code class="docutils literal notranslate"><span class="pre">pydevd</span></code> package on the <code class="docutils literal notranslate"><span class="pre">PYTHONPATH</span></code>. The following code does so at runtime:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span class="n">PYTHON_ROOT</span><span class="o">=</span><span class="s2">"<Change this to point to a Python installation that has pydevd installed>"</span>
<span class="c1"># PYTHON_ROOT="c:/users/<username>/apps/miniconda3"</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">PYTHON_ROOT</span><span class="p">,</span> <span class="s2">"lib/site-packages"</span><span class="p">))</span>
<span class="kn">import</span> <span class="nn">pydevd</span>
<span class="n">pydevd</span><span class="o">.</span><span class="n">settrace</span><span class="p">(</span><span class="s1">'localhost'</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">44444</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>
<p>A Remote Debugging configration needs to be setup to use the <code class="docutils literal notranslate"><span class="pre">44444</span></code> port (can be changed, but it needs to be reflected in the code), and running before the tests are run!</p>
<p>The <code class="docutils literal notranslate"><span class="pre">pydevd</span></code> package does not have to be installed on Python 2. As of 12/11/2018 installing <code class="docutils literal notranslate"><span class="pre">pydevd</span></code> on a separate installation with Python 3.7, and adding the code above successfully connects.</p>
</div>
<div class="section" id="setting-up-pycharm-on-linux">
<h2><a class="toc-backref" href="#id8">Setting up PyCharm on Linux</a><a class="headerlink" href="#setting-up-pycharm-on-linux" title="Permalink to this headline">¶</a></h2>
<ol class="arabic">
<li><p class="first">Use the native python interpreter (<code class="docutils literal notranslate"><span class="pre">/usr/bin/python2.7</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/python2.7/python.exe</span></code></p>
</li>
<li><p class="first">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><Mantid Source Directory>/scripts
<Mantid Source Directory>/Framework/PythonInterface
<Mantid Source Directory>/qt/applications/workbench
<Mantid Source Directory>/qt/widgets
<Mantid Source 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><Mantid Build 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 class="first">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>
</div>
<div class="section" id="useful-plugins">
<h2><a class="toc-backref" href="#id9">Useful Plugins</a><a class="headerlink" href="#useful-plugins" title="Permalink to this headline">¶</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><strong>Markdown support</strong> - Side by side rendering of markdown documents such as``.md`` , <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)</li>
<li><strong>dotplugin</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">DOT</span></code></li>
<li><strong>BashSupport</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">BASH</span></code> scripts</li>
<li><strong>CMD Support</strong> - Syntax highlighting for <code class="docutils literal notranslate"><span class="pre">.BAT</span></code> ~scripts</li>
</ul>
<p>Please add to this list if you find a useful plugin of your own</p>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<ul class="nav navbar-nav" style=" float: right;">
<li>
<a href="VisualStudioBuildImpact.html" title="Previous Chapter: Visual Studio Build Impact"><span class="glyphicon glyphicon-chevron-left visible-sm"></span><span class="hidden-sm hidden-tablet">« Visual Studio...</span>
</a>
</li>
<li>
<a href="VSCode.html" title="Next Chapter: VSCode"><span class="glyphicon glyphicon-chevron-right visible-sm"></span><span class="hidden-sm hidden-tablet">VSCode »</span>
</a>
</li>
<li><a href="#">Back to top</a></li>
</ul>
<p>
</p>
</div>
</footer>
</body>
</html>