Added NINJA-IDE to IDEs
[python-guide.git] / docs / dev / env.rst
1 Your Development Environment
2 ============================
3
4
5 Text Editors
6 ::::::::::::
7
8 Just about anything which can edit plain text will work for writing Python code,
9 however, using a more powerful editor may make your life a bit easier.
10
11
12 VIM
13 ---
14
15 Vim is a text editor which uses keyboard shortcuts for editing instead of menus
16 or icons. There exist a couple of plugins and settings for the VIM editor to
17 aid python development. If you only develop in Python, a good start is to set
18 the default settings for indentation and line-wrapping to values compliant with
19 `PEP 8 <http://www.python.org/dev/peps/pep-0008/>`_. In your home directory,
20 open a file called `.vimrc` and add the following lines:::
21
22     set textwidth=79
23     set shiftwidth=4
24     set tabstop=4
25     set expandtab
26     set softtabstop=4
27     set shiftround
28
29 With these settings, newlines are inserted after 79 characters and indentation
30 is set to 4 spaces per tab. If you also use VIM for other languages, there is a
31 handy plugin at indent_, which handles indentation settings for python source
32 files.
33
34 There is also a handy syntax plugin at syntax_ featuring some improvements over
35 the syntax file included in VIM 6.1.
36
37 These plugins supply you with a basic environment for developing in Python.
38 To get the most out of Vim, you should continually check your code for syntax
39 errors and PEP8 compliance. Luckily PEP8_ and Pyflakes_ will do this for you.
40 If your VIM is compiled with `+python` you can also utilize some very handy
41 plugins to do these checks from within the editor.
42
43 For PEP8 checking, install the vim-pep8_ plugin, and for pyflakes you can
44 install vim-pyflakes_. Now you can map the functions `Pep8()` or `Pyflakes()`
45 to any hotkey or action you want in Vim. Both plugins will display errors at
46 the bottom of the screen, and provide an easy way to jump to the corresponding
47 line. It's very handy to call these functions whenever you save a file. In
48 order to do this, add the following lines to your `vimrc`::
49
50     autocmd BufWritePost *.py call Pyflakes()
51     autocmd BufWritePost *.py call Pep8()
52
53 If you are already using syntastic_ you can enable it to run Pyflakes on write
54 and show errors and warnings in the quickfix window. An example configuration
55 to do that which also shows status and warning messages in the statusbar would be::
56
57     set statusline+=%#warningmsg#
58     set statusline+=%{SyntasticStatuslineFlag()}
59     set statusline+=%*
60     let g:syntastic_auto_loc_list=1
61     let g:syntastic_loc_list_height=5
62
63 Python-mode
64 ^^^^^^^^^^^
65
66 Python-mode_ is complex solution in VIM for work with python code.
67 It has:
68
69 - Async python code checking (pylint, pyflakes, pep8, mccabe) in any combination;
70 - Code refactoring and autocompletion with Rope;
71 - Fastest python folding;
72 - Nice and powered python syntax;
73 - Virtual env support;
74 - Search by python documentation and run python code;
75 - More other things like auto pep8 error fixes;
76 - Very customizable an documented as well;
77 - Have all required libraries in self;
78
79 And more stuff.
80
81
82 .. _indent: http://www.vim.org/scripts/script.php?script_id=974
83 .. _syntax: http://www.vim.org/scripts/script.php?script_id=790
84 .. _Pyflakes: http://pypi.python.org/pypi/pyflakes/
85 .. _vim-pyflakes: https://github.com/nvie/vim-pyflakes
86 .. _PEP8: http://pypi.python.org/pypi/pep8/
87 .. _vim-pep8: https://github.com/nvie/vim-pep8
88 .. _syntastic: https://github.com/scrooloose/syntastic
89 .. _Python-mode: https://github.com/klen/python-mode
90
91 .. todo:: add supertab notes
92
93 Emacs
94 -----
95
96 Emacs is a powerful text editor. It's fully programmable (lisp), but
97 it can be some work to wire up correctly. A good start if you're
98 already an Emacs user is `Python Programming in Emacs`_ at EmacsWiki.
99
100 1. Emacs itself comes with a python mode.
101 2. Python ships with an alternate version:
102    `python-mode.el <https://launchpad.net/python-mode>`_
103 3. Fabián Ezequiel Gallina's provides nice functionality and
104    behavior out of the box: `python.el <https://github.com/fgallina/python.el>`_
105
106 .. _Python Programming in Emacs: http://emacswiki.org/emacs/PythonProgrammingInEmacs
107
108 TextMate
109 --------
110
111 "`TextMate <http://macromates.com/>`_ brings Apple's approach to operating
112 systems into the world of text editors. By bridging UNIX underpinnings and GUI,
113 TextMate cherry-picks the best of both worlds to the benefit of expert
114 scripters and novice users alike."
115
116 Sublime Text
117 ------------
118
119 "`Sublime Text <http://www.sublimetext.com/>`_ is a sophisticated text editor
120 for code, html and prose. You'll love the slick user interface and
121 extraordinary features."
122
123 Sublime Text has excellent support for editing Python code and uses Python for
124 its plugin API.
125
126 IDEs
127 ::::
128
129 PyCharm / IntelliJ IDEA
130 -----------------------
131
132 `PyCharm <http://www.jetbrains.com/pycharm/>`_ is developed by JetBrains, also
133 known for IntelliJ IDEA. Both share the same code base and most of PyCharm's
134 features can be brought to IntelliJ with the free `Python Plug-In <http://plugins.intellij.net/plugin/?id=631/>`_.
135
136
137 Eclipse
138 -------
139
140 The most popular Eclipse plugin for Python development is Aptana's
141 `PyDev <http://pydev.org>`_.
142
143
144 Komodo IDE
145 ----------
146 `Komodo IDE <http://www.activestate.com/komodo-ide>`_ is developed by
147 ActiveState and is a commercial IDE for Windows, Mac
148 and Linux.
149
150
151 Spyder
152 ------
153
154 `Spyder <http://code.google.com/p/spyderlib/>`_ an IDE specifically geared
155 toward working with scientific python libraries (namely `Scipy <http://www.scipy.org/>`_).
156 Includes integration with pyflakes_, `pylint <http://www.logilab.org/857>`_,
157 and `rope <http://rope.sourceforge.net/>`_.
158
159 Spyder is open-source (free), offers code completion, syntax highlighting,
160 class and function browser, and object inspection.
161
162
163 WingIDE
164 -------
165
166 `WingIDE <http://wingware.com/>`_ a python specific IDE.   Runs for Linux,
167 Windows, and Mac (as an X11 application, which frustrates some Mac users).
168
169
170 NINJA-IDE
171 ---------
172
173 `NINJA-IDE <http://www.ninja-ide.org/>`_ (from the recursive acronym: "Ninja-IDE
174 Is Not Just Another IDE", is a cross-platform IDE, specially designed to build
175 Python applications, and runs on Linux/X11, Mac OS X and Windows desktop operating
176 systems. Installers for these platforms can be downloaded from the website.
177
178 NINJA-IDE is open-source software (GPLv3 licence) and is developed in Python and
179 Qt. The source files can be downloaded from `GitHub <https://github.com/ninja-ide>`_.
180
181 Interpreter Tools
182 :::::::::::::::::
183
184
185 virtualenv
186 ----------
187
188 Virtualenv is a tool to keep the dependencies required by different projects
189 in separate places, by creating virtual Python environments for them.
190 It solves the "Project X depends on version 1.x but, Project Y needs 4.x"
191 dilemma and keeps your global site-packages directory clean and manageable.
192
193 `virtualenv <http://www.virtualenv.org/en/latest/index.html>`_ creates
194 a folder which contains all the necessary executables to contain the
195 packages that a Python project would need. An example workflow is given.
196
197 Install virtualenv::
198
199     $ pip install virtualenv
200
201
202 Create a virtual environment for a project::
203
204     $ cd my_project
205     $ virtualenv venv
206
207 ``virtualenv venv`` will create a folder in the current directory
208 which will contain the Python executable files, and a copy of the ``pip``
209 library which you can use to install other packages. The name of the
210 virtual environment (in this case, it was ``venv``) can be anything;
211 omitting the name will place the files in the current directory instead.
212
213 In order the start using the virtual environment, run::
214
215     $ source venv/bin/activate
216
217
218 The name of the current virtual environment will now appear on the left
219 of the prompt (e.g. ``(venv)Your-Computer:your_project UserName$``) to
220 let you know that it's active. From now on, any package that you install
221 using ``pip`` will be placed in the venv folder, isolated from the global
222 Python installation. Install packages as usual::
223
224     $ pip install requests
225
226 To stop using an environment simply type ``deactivate``. To remove the
227 environment, just remove the directory it was installed into. (In this
228 case, it would be ``rm -rf venv``).
229
230 Other Notes
231 ^^^^^^^^^^^
232
233 Running ``virtualenv`` with the option ``--no-site-packages`` will not
234 include the packages that are installed globally. This can be useful
235 for keeping the package list clean in case it needs to be accessed later.
236
237 In order to keep your environment consistent, it's a good idea to "freeze"
238 the current state of the environment packages. To do this, run
239
240 ::
241
242     $ pip freeze > requirements.txt
243
244 This will create a ``requirements.txt`` file, which contains a simple
245 list of all the packages in the current environment, and their respective
246 versions. Later, when a different developer (or you, if you need to re-
247 create the environment) can install the same packages, with the same
248 versions by running
249
250 ::
251
252     $ pip install -r requirements.txt
253
254 This can help ensure consistency across installations, across deployments,
255 and across developers.
256
257 Lastly, remember to exclude the virtual environment folder from source
258 control by adding it to the ignore list.
259
260 virtualenvwrapper
261 -----------------
262
263 `Virtualenvwrapper <http://pypi.python.org/pypi/virtualenvwrapper>`_ makes
264 virtualenv a pleasure to use by wrapping the command line API with a nicer CLI.
265
266 ::
267
268     $ pip install virtualenvwrapper
269
270
271 Put this into your `~/.bash_profile` (Linux/Mac) file:
272
273 ::
274
275     $ export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
276
277 This will prevent your virtualenvs from relying on your (global) site packages
278 directory, so that they are completely separate..
279
280 Other Tools
281 :::::::::::
282
283 IDLE
284 ----
285
286 `IDLE <http://docs.python.org/library/idle.html>`_ is an integrated
287 development environment that is part of Python standard library. It is
288 completely written in Python and uses Tkinter GUI toolkit. Though IDLE
289 is not suited for full-blown development using Python , it is quite
290 helpful to try out small Python snippets and experiment with different
291 features in Python.
292
293 It provides following features:
294
295 * Python Shell Window (interpreter)
296 * Multi window text editor that colorizes Python code
297 * Minimal debugging facility
298
299
300 IPython
301 -------
302
303 `IPython <http://ipython.org/>`_ provides a rich toolkit to help you make the
304 most out of using Python interactively. Its main components are:
305
306 * Powerful Python shells (terminal- and Qt-based).
307 * A web-based notebook with the same core features but support for rich media,
308   text, code, mathematical expressions and inline plots.
309 * Support for interactive data visualization and use of GUI toolkits.
310 * Flexible, embeddable interpreters to load into your own projects.
311 * Tools for high level and interactive parallel computing.
312
313 ::
314
315     $ pip install ipython
316
317
318
319 BPython
320 -------
321
322 `bpython <http://bpython-interpreter.org/>`_ is an alternative interface to the
323 Python interpreter for Unix-like operating systems. It has the following features:
324
325 * In-line syntax highlighting.
326 * Readline-like autocomplete with suggestions displayed as you type.
327 * Expected parameter list for any Python function.
328 * "Rewind" function to pop the last line of code from memory and re-evaluate.
329 * Send entered code off to a pastebin.
330 * Save entered code to a file.
331 * Auto-indentation.
332 * Python 3 support.
333
334 ::
335
336     $ pip install bpython
337