Your Development Environment
Just about anything that can edit plain text will work for writing Python code;however, using a more powerful editor may make your life a bit easier.
Vim is a text editor which uses keyboard shortcuts for editing instead of menusor icons. There are a couple of plugins and settings for the Vim editor toaid Python development. If you only develop in Python, a good start is to setthe default settings for indentation and line-wrapping to values compliant withPEP 8. In your home directory, open a file called and add thefollowing lines:
With these settings, newlines are inserted after 79 characters and indentationis set to 4 spaces per tab. If you also use Vim for other languages, there is ahandy plugin called , which handles indentation settings for Pythonsource files.
There is also a handy syntax plugin called syntax featuring some improvementsover the syntax file included in Vim 6.1.
These plugins supply you with a basic environment for developing in Python. Toget the most out of Vim, you should continually check your code for syntaxerrors and PEP8 compliance. Luckily and Pyflakes will do thisfor you. If your Vim is compiled with +python
you can also utilize somevery handy plugins to do these checks from within the editor.
For PEP8 checking and pyflakes, you can install . Now you can map thefunction Flake8
to any hotkey or action you want in Vim. The plugin willdisplay errors at the bottom of the screen, and provide an easy way to jump tothe corresponding line. It’s very handy to call this function whenever you savea file. In order to do this, add the following line to your.vimrc
:
- autocmd BufWritePost *.py call Flake8()
If you are already using syntastic, you can set it to run Pyflakes on writeand show errors and warnings in the quickfix window. An example configurationto do that which also shows status and warning messages in the statusbar wouldbe:
Python-mode
Python-mode is a complex solution for working with Python code in Vim.It has:
- Asynchronous Python code checking (
pylint
,pyflakes
, ,mccabe
) in any combination - Code refactoring and autocompletion with Rope
- Fast Python folding
- Virtualenv support
- Search through Python documentation and run Python code
- Auto error fixes
And more.
SuperTab
is a small Vim plugin that makes code completion more convenient byusing <Tab>
key or any other customized keys.
Emacs
Emacs is another powerful text editor. It is fully programmable (Lisp), butit can be some work to wire up correctly. A good start if you’re already anEmacs user is at EmacsWiki.
- Emacs itself comes with a Python mode.
TextMate
Sublime Text
Sublime Text has excellent support for editing Python code and uses Python forits plugin API. It also has a diverse variety of plugins,some of which allow forin-editor PEP8 checking and code “linting”.
Atom
PyCharm / IntelliJ IDEA
is developed by JetBrains, alsoknown for IntelliJ IDEA. Both share the same code base and most of PyCharm’sfeatures can be brought to IntelliJ with the freePython Plug-In. There are twoversions of PyCharm: Professional Edition (Free 30-day trial) and CommunityEdition (Apache 2.0 License) with fewer features.
is an extension for the Visual Studio Code IDE.This is a free, lightweight, open source IDE, with support for Mac, Windows, and Linux.Built using open source technologies such as Node.js and Python, with compelling features such as Intellisense (autocompletion), local and remote debugging, linting, and the like.
MIT licensed.
Enthought Canopy
Enthought Canopy is a PythonIDE which is focused towards Scientists and Engineers as it provides preinstalled libraries for data analysis.
Eclipse
The most popular Eclipse plugin for Python development is Aptana’sPyDev.
Komodo IDE
Komodo IDE is developed byActiveState and is a commercial IDE for Windows, Mac, and Linux. is the open sourcealternative.
Spyder
is an IDE specifically gearedtoward working with scientific Python libraries (namelySciPy). It includes integration with ,pylint and.
Spyder is open source (free), offers code completion, syntax highlighting,a class and function browser, and object inspection.
WingIDE
is a Python specific IDE. It runs on Linux,Windows, and Mac (as an X11 application, which frustrates some Mac users).
WingIDE offers code completion, syntax highlighting, source browser, graphicaldebugger and support for version control systems.
NINJA-IDE (from the recursive acronym: “Ninja-IDEIs Not Just Another IDE”) is a cross-platform IDE, specially designed to buildPython applications, and runs on Linux/X11, Mac OS X, and Windows desktopoperating systems. Installers for these platforms can be downloaded from thewebsite.
Eric (The Eric Python IDE)
Eric is a full featured Python IDEoffering source code autocompletion, syntax highlighting, support for versioncontrol systems, Python 3 support, integrated web browser, python shell,integrated debugger, and a flexible plug-in system. Written in Python, it isbased on the Qt GUI toolkit, integrating the Scintilla editor control. Ericis an open source software project (GPLv3 licence) with more than ten years ofactive development.
Virtual Environments
Virtual Environments provide a powerful way to isolate project package dependencies. This means that you can use packages particular to a Python project without installing them system wide and thus avoiding potential version conflicts.
To start using and see more information:Virtual Environments docs.
pyenv
pyenv is a tool to allow multiple versionsof the Python interpreter to be installed at the same time. This solves theproblem of having different projects requiring different versions of Python.For example, it becomes very easy to install Python 2.7 for compatibility inone project, while still using Python 3.4 as the default interpreter.pyenv isn’t just limited to the CPython versions – it will also install PyPy,Anaconda, miniconda, stackless, Jython, and IronPython interpreters.
pyenv works by filling a shims
directory with fake versions of the Pythoninterpreter (plus other tools like pip
and 2to3
). When the systemlooks for a program named , it looks inside the shims
directoryfirst, and uses the fake version, which in turn passes the command on topyenv. pyenv then works out which version of Python should be run based onenvironment variables, .python-version
files, and the global default.
pyenv isn’t a tool for managing virtual environments, but there is the plugin which automatesthe creation of different environments, and also makes it possible to use theexisting pyenv tools to switch to different environments based on environmentvariables or .python-version
files.
IDLE
is an integrated development environment that ispart of the Python standard distribution. It is completely written in Python and usesthe Tkinter GUI toolkit. Though IDLE is not suited for full-blown developmentusing Python, it is quite helpful to try out small Python snippets andexperiment with different features in Python.
It provides the following features:
- Python Shell Window (interpreter)
- Multi window text editor that colorizes Python code
- Minimal debugging facility
IPython
provides a rich toolkit to help you make themost out of using Python interactively. Its main components are:
- Powerful Python shells (terminal- and Qt-based)
- A web-based notebook with the same core features but support for rich media,text, code, mathematical expressions and inline plots
- Flexible, embeddable interpreters to load into your own projects
- Tools for high level and interactive parallel computing
- $ pip install ipython
To download and install IPython with all its optional dependencies for the notebook, qtconsole, tests, and other functionalities:
bpython is an alternative interface to thePython interpreter for Unix-like operating systems. It has the followingfeatures:
- In-line syntax highlighting
- Readline-like autocomplete with suggestions displayed as you type
- Expected parameter list for any Python function
- “Rewind” function to pop the last line of code from memory and re-evaluate
- Send entered code off to a pastebin
- Save entered code to a file
- Auto-indentation
- Python 3 support
- $ pip install bpython
ptpython
- Syntax highlighting
- Autocompletion
- Multiline editing
- Emacs and Vim Modes
- Embedding REPL inside of your code
- Syntax validation
- Tab pages