Seu ambiente de desenvolvimento

../_images/33175624924_7febc46cc4_k_d.jpg

Editores de texto

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

O Vim é um editor de textos que utiliza atalhos do teclado para a edição, ao invés de menus ou ícones. Existem alguns plugins e configurações para o Vim que auxiliam o desenvolvimento em Python. Se você desenvolve apenas em Python, um bom começo é definir as configurações padrão para indentação e quebras de linha para valores compatíveis com aPEP 8. Em seu diretório inicial, abra um arquivo chamado.vimrc e adicione as seguintes linhas:

settextwidth=79" lines longer than 79 columns will be brokensetshiftwidth=4" operation >> indents 4 columns; << unindents 4 columnssettabstop=4" a hard TAB displays as 4 columnssetexpandtab" insert spaces when hitting TABssetsofttabstop=4" insert/delete 4 spaces when hitting a TAB/BACKSPACEsetshiftround" round indent to multiple of 'shiftwidth'setautoindent" align the new line indent with the previous line

Com essas configurações, novas linhas são inseridas após 79 caracteres e a indentação é programada para 4 espaços por pressionamento da tecla tab. Se você também usa Vim para outra línguas, existe um ótimo plugin chamadoindent, que cuida da configuração da indentação para arquivos de origem do Python.

Também há um plugin de sintaxe muito prático chamadosyntax, que apresenta algumas evoluções quando comparado ao arquivo de sintaxe incluído no 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. Luckilypycodestyle andPyflakes 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.

Para checagens de PEP8 e pyflakes, você pode instalar ovim-flake8. Agora você pode mapear a funçãoFlake8 para qualquer tecla de atalho ou ação que desejar no Vim. O plugin vai mostrar os erros no lado inferior da tela, e fornecer uma maneira simples de saltar para a linha correspondente. É muito útil chamar essa função sempre que você salvar um arquivo. Para fazer isso, adicione a seguinte linha ao seu.vimrc:

autocmdBufWritePost*.pycallFlake8()

Se você já utilizasyntasic, você pode configurar ele para rodar Pyflakes na escrita e mostrar erros e advertências na janela de consertos rápidos. Um exemplo de configuração que faça isso e que também mostre o status e mensagens de advertência na barra de status pode ser:

setstatusline+=%#warningmsg#setstatusline+=%{SyntasticStatuslineFlag()}setstatusline+=%*letg:syntastic_auto_loc_list=1letg:syntastic_loc_list_height=5

Python-mode

Python-mode é uma solução complexa para trabalhar com código em Python no Vim. Ele tem:

  • Asynchronous Python code checking (pylint,pyflakes,pycodestyle,mccabe) in any combination
  • Refatoração de código e auto-completar com Rope
  • Dobra rápida Python
  • Suporte virtualenv
  • Busca através da documentação Python e execução de código Python
  • Autopycodestyle error fixes

E mais.

SuperTab

SuperTab é um pequeno plugin de Vim que faz a função de auto-completar mais conveniente utilizando-se a tecla<Tab> ou qualquer outra tecla customizada.

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 isPython Programming in Emacs at EmacsWiki.

  1. O próprio Emacs vem com o modo Python

TextMate

TextMate brings Apple’s approach to operatingsystems into the world of text editors. By bridging Unix underpinnings andGUI, TextMate cherry-picks the best of both worlds to the benefit of expertscripters and novice users alike.

Sublime Text

Sublime Text is a sophisticated texteditor for code, markup, and prose. You’ll love the slick user interface,extraordinary features, and amazing performance.

O Sublime Text possuí um suporte excelente para edição de código Python além de usar Python em sua API de plugins. Ele também possuí uma grande variedade de plugins,dos quais habilitam checagem de PEP8 no editor e “linting” de código.

Atom

Atom é um editor de texto para o século XXI, altamente extensível, construído sobre o atom-shell e baseado em tudo o que amamos nos nossos editores favoritos.

Atom is web native (HTML, CSS, JS), focusing on modular design and easy plugindevelopment. It comes with native package control and a plethora of packages.Recommended for Python development isLinter combined withlinter-flake8.

Python (no Visual Studio Code)

Python for Visual Studio is an extension for theVisual Studio Code.This is a free, lightweight, open source code editor, 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.

licenciado MIT.

IDEs

PyCharm / IntelliJ IDEA

PyCharm 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.

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.

IDE Komodo

Komodo IDE is developed byActiveState and is a commercial IDE for Windows, Mac, and Linux.KomodoEdit is the open sourcealternative.

Spyder

Spyder is an IDE specifically gearedtoward working with scientific Python libraries (namelySciPy). It includes integration withpyflakes,pylint andrope.

Spyder is open source (free), offers code completion, syntax highlighting,a class and function browser, and object inspection.

WingIDE

WingIDE is a Python specific IDE. It runs on Linux,Windows, and Mac (as an X11 application, which frustrates some Mac users).

WingIDE oferece autocompletar, destacamento de sintaxe, browser nativo, debugger gráfico e suporte para sistemas de controle de versão.

NINJA-IDE

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.

NINJA-IDE is open source software (GPLv3 licence) and is developedin Python and Qt. The source files can be downloaded fromGitHub.

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.

Mu

Mu is a minimalist Python IDE which can run Python 3 codelocally and can also deploy code to the BBC micro:bit and to Adafruit boards runningCircuitPython.

Intended for beginners, mu includes a Python 3 interpreter, and is easy to installon Windows, OS/X and Linux. It runs well on the Raspberry Pi.

There’s an active support community on gitter.

Ferramentas do intérprete

Ambientes virtuais

Ambientes virtuais fornecem um meio poderoso para isolar dependências de pacotes do seu projeto. Isso significa que você pode usar pacotes particulares para um projeto em Python sem instalar eles em todo o seu sistema, evitando potenciais conflitos de versão.

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 ashims directory with fake versions of the Pythoninterpreter (plus other tools likepip and2to3). When the systemlooks for a program namedpython, it looks inside theshims 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 pluginpyenv-virtualenv 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.

Outras ferramentas

IDLE

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.

Ele provê as seguintes funcionalidades:

  • Janela terminar do Python (intérprete)
  • Editor de texto com múltiplas janelas que coloriza código em Python
  • Instalação de depuração mínima

IPython

O IPython oferece um kit de ferramentas para ajudar a você usar o Python interativamente. Seus principais componentes são:

  • 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
  • Support for interactive data visualization and use of GUI toolkits
  • 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:

$ pip install ipython[all]

BPython

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

ptpython is a REPL buildon top of theprompt_toolkitlibrary. It is considered to be an alternative toBPython. Features include:

  • Realce de sintaxe
  • Autocompletado
  • Edição multi linha
  • Emacs and Vim Modes
  • Embedding REPL inside of your code
  • Syntax validation
  • Tab pages
  • Support for integrating withIPython’s shell, by installing IPython(pipinstallipython) and runningptipython.
$ pip install ptpython