mirror of
https://github.com/kennethreitz-archive/conductofcode.git
synced 2026-06-05 15:20:17 +00:00
352 lines
19 KiB
HTML
352 lines
19 KiB
HTML
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>Your Development Environment — pythonguide 0.0.1 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../_static/flasky.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../',
|
|
VERSION: '0.0.1',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</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>
|
|
<link rel="top" title="pythonguide 0.0.1 documentation" href="../index.html" />
|
|
<link rel="next" title="Virtual Environments" href="virtualenvs.html" />
|
|
<link rel="prev" title="Linux" href="../starting/install/linux.html" />
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
|
|
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="virtualenvs.html" title="Virtual Environments"
|
|
accesskey="N">next</a> |</li>
|
|
<li class="right" >
|
|
<a href="../starting/install/linux.html" title="Linux"
|
|
accesskey="P">previous</a> |</li>
|
|
<li><a href="../index.html">pythonguide 0.0.1 documentation</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<div class="section" id="your-development-environment">
|
|
<h1>Your Development Environment<a class="headerlink" href="#your-development-environment" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="text-editors">
|
|
<h2>Text Editors<a class="headerlink" href="#text-editors" title="Permalink to this headline">¶</a></h2>
|
|
<p>Just about anything which can edit plain text will work for writing Python code,
|
|
however, using a more powerful editor may make your life a bit easier.</p>
|
|
<div class="section" id="vim">
|
|
<h3>VIM<a class="headerlink" href="#vim" title="Permalink to this headline">¶</a></h3>
|
|
<p>There exist a couple of plugins and settings for the VIM editor to aid python
|
|
development. If you only develop in Python, a good start is to set the default
|
|
settings for indentation and linewrapping to values compliant with PEP8:</p>
|
|
<div class="highlight-python"><pre>set textwidth=79
|
|
set shiftwidth=4
|
|
set tabstop=4
|
|
set expandtab
|
|
set softtabstop=4
|
|
set shiftround</pre>
|
|
</div>
|
|
<p>With these settings newlines are inserted after 79 characters and indentation
|
|
is set to 4 spaces per tab. If you also use VIM for other languages, there is a
|
|
handy plugin at <a class="reference external" href="http://www.vim.org/scripts/script.php?script_id=974">indent</a>, which handles indentation settings for python source
|
|
files.
|
|
Additionally there is also a handy syntax plugin at <a class="reference external" href="http://www.vim.org/scripts/script.php?script_id=790">syntax</a> featuring some
|
|
improvements over the syntax file included in VIM 6.1.</p>
|
|
<p>These plugins supply you with a basic environment for developing in Python.
|
|
However in order to improve the programming flow we also want to continually
|
|
check for PEP8 compliance and check syntax. Luckily there exist <a class="reference external" href="http://pypi.python.org/pypi/pep8/">PEP8</a> and
|
|
<a class="reference external" href="http://pypi.python.org/pypi/pyflakes/">Pyflakes</a> to do this for you. If your VIM is compiled with <cite>+python</cite> you can
|
|
also utilize some very handy plugins to do these checks from within the editor.
|
|
For PEP8 checking install <a class="reference external" href="https://github.com/nvie/vim-pep8">vim-pep8</a>. Now you can map the vim function
|
|
<cite>Pep8()</cite> to any hotkey or action you want. Similarly for pyflakes you can
|
|
install <a class="reference external" href="https://github.com/nvie/vim-pyflakes">vim-pyflakes</a>. Now you can map <cite>Pyflakes()</cite> like the PEP8 function and
|
|
have it called quickly. Both plugins will display errors in a quickfix list and
|
|
provide an easy way to jump to the corresponding line. A very handy setting is
|
|
calling these functions whenever a buffer is saved. In order to do this, enter
|
|
the following lines into your vimrc:</p>
|
|
<div class="highlight-python"><pre>autocmd BufWritePost *.py call Pyflakes()
|
|
autocmd BufWritePost *.py call Pep8()</pre>
|
|
</div>
|
|
<div class="admonition-todo admonition" id="index-0">
|
|
<p class="first admonition-title">Todo</p>
|
|
<p class="last">add supertab notes</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="textmate">
|
|
<h3>TextMate<a class="headerlink" href="#textmate" title="Permalink to this headline">¶</a></h3>
|
|
<p>“<a class="reference external" href="http://macromates.com/">TextMate</a> brings Apple’s approach to operating systems into the world of text editors. By bridging UNIX underpinnings and GUI, TextMate cherry-picks the best of both worlds to the benefit of expert scripters and novice users alike.”</p>
|
|
</div>
|
|
<div class="section" id="sublime-text">
|
|
<h3>Sublime Text<a class="headerlink" href="#sublime-text" title="Permalink to this headline">¶</a></h3>
|
|
<p>“<a class="reference external" href="http://www.sublimetext.com/">Sublime Text</a> is a sophisticated text editor
|
|
for code, html and prose. You’ll love the slick user interface and
|
|
extraordinary features.”</p>
|
|
<p>Sublime Text has excellent support for editing Python code and uses Python for
|
|
its plugin API.</p>
|
|
<p><a class="reference external" href="http://www.sublimetext.com/blog/articles/sublime-text-2-beta">Sublime Text 2</a> is currently in beta.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="ides">
|
|
<h2>IDEs<a class="headerlink" href="#ides" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="pycharm-intellij-idea">
|
|
<h3>PyCharm / IntelliJ IDEA<a class="headerlink" href="#pycharm-intellij-idea" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://www.jetbrains.com/pycharm/">PyCharm</a> is developed by JetBrains, also known for IntelliJ IDEA. Both share the same code base and most of PyCharm’s features can be brought to IntelliJ with the free <a class="reference external" href="http://plugins.intellij.net/plugin/?id=631/">Python Plug-In</a>.</p>
|
|
</div>
|
|
<div class="section" id="eclipse">
|
|
<h3>Eclipse<a class="headerlink" href="#eclipse" title="Permalink to this headline">¶</a></h3>
|
|
<p>The most popular Eclipse plugin for Python development is Aptana’s
|
|
<a class="reference external" href="http://pydev.org">PyDev</a>.</p>
|
|
</div>
|
|
<div class="section" id="komodo-ide">
|
|
<h3>Komodo IDE<a class="headerlink" href="#komodo-ide" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://www.activestate.com/komodo-ide">Komodo IDE</a> is developed by ActiveState and is a commerical IDE for Windows, Mac
|
|
and Linux.</p>
|
|
</div>
|
|
<div class="section" id="spyder">
|
|
<h3>Spyder<a class="headerlink" href="#spyder" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://code.google.com/p/spyderlib/">Spyder</a> an IDE specifically geared toward working with scientific python libraries (namely <a class="reference external" href="http://www.scipy.org/">Scipy</a>).
|
|
Includes integration with <a class="reference external" href="http://pypi.python.org/pypi/pyflakes/">pyflakes</a>, <a class="reference external" href="http://www.logilab.org/857">pylint</a>,
|
|
and <a class="reference external" href="http://rope.sourceforge.net/">rope</a>.</p>
|
|
<p>Spyder is open-source (free), offers code completion, syntax highlighting, class and function browser, and object inspection.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="interpreter-tools">
|
|
<h2>Interpreter Tools<a class="headerlink" href="#interpreter-tools" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="virtualenv">
|
|
<h3>virtualenv<a class="headerlink" href="#virtualenv" title="Permalink to this headline">¶</a></h3>
|
|
<p>Virtualenv is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them.
|
|
It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma and keeps your global site-packages directory clean and manageable.</p>
|
|
<p><a class="reference external" href="http://www.virtualenv.org/en/latest/index.html">virtualenv</a> creates
|
|
a folder which contains all the necessary executables to contain the
|
|
packages that a Python project would need. An example workflow is given.</p>
|
|
<p>Install virtualenv:</p>
|
|
<div class="highlight-python"><pre>$ pip install virtualenv</pre>
|
|
</div>
|
|
<p>Create a virtual environment for a project:</p>
|
|
<div class="highlight-python"><pre>$ cd my_project
|
|
$ virtualenv venv</pre>
|
|
</div>
|
|
<p><tt class="docutils literal"><span class="pre">virtualenv</span> <span class="pre">venv</span></tt> will create a folder in the currect directory
|
|
which will contain the Python executable files, and a copy of the <tt class="docutils literal"><span class="pre">pip</span></tt>
|
|
library which you can use to install other packages. The name of the
|
|
virtual environment (in this case, it was <tt class="docutils literal"><span class="pre">venv</span></tt>) can be anything;
|
|
omitting the name will place the files in the current directory instead.</p>
|
|
<p>In order the start using the virtual environment, run:</p>
|
|
<div class="highlight-python"><pre>$ source venv/bin/activate</pre>
|
|
</div>
|
|
<p>The name of the current virtual environment will now appear on the left
|
|
of the prompt (e.g. <tt class="docutils literal"><span class="pre">(venv)Your-Computer:your_project</span> <span class="pre">UserName$</span></tt>) to
|
|
let you know that it’s active. From now on, any package that you install
|
|
using <tt class="docutils literal"><span class="pre">pip</span></tt> will be placed in the venv folder, isolated from the global
|
|
Python installation. Install packages as usual:</p>
|
|
<div class="highlight-python"><pre>$ pip install requests</pre>
|
|
</div>
|
|
<p>To stop using an environment simply type <tt class="docutils literal"><span class="pre">deactivate</span></tt>. To remove the
|
|
environment, just remove the directory it was installed into. (In this
|
|
case, it would be <tt class="docutils literal"><span class="pre">rm</span> <span class="pre">-rf</span> <span class="pre">venv</span></tt>).</p>
|
|
<div class="section" id="other-notes">
|
|
<h4>Other Notes<a class="headerlink" href="#other-notes" title="Permalink to this headline">¶</a></h4>
|
|
<p>Running <tt class="docutils literal"><span class="pre">virtualenv</span></tt> with the option <tt class="docutils literal"><span class="pre">--no-site-packages</span></tt> will not
|
|
include the packages that are installed globally. This can be useful
|
|
for keeping the package list clean in case it needs to be accessed later.</p>
|
|
<p>In order to keep your environment consistent, it’s a good idea to “freeze”
|
|
the current state of the environment packages. To do this, run</p>
|
|
<div class="highlight-python"><pre>$ pip freeze > requirements.txt</pre>
|
|
</div>
|
|
<p>This will create a <tt class="docutils literal"><span class="pre">requirements.txt</span></tt> file, which contains a simple
|
|
list of all the packages in the current environment, and their respective
|
|
versions. Later, when a different developer (or you, if you need to re-
|
|
create the environment) can install the same packages, with the same
|
|
versions by running</p>
|
|
<div class="highlight-python"><pre>$ pip install -r requirements.txt</pre>
|
|
</div>
|
|
<p>This can help ensure consistency across installations, across deployments,
|
|
and across developers.</p>
|
|
<p>Lastly, remember to exclude the virtual environment folder from source
|
|
control by adding it to the ignore list.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="virtualenvwrapper">
|
|
<h3>virtualenvwrapper<a class="headerlink" href="#virtualenvwrapper" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://pypi.python.org/pypi/virtualenvwrapper">Virtualenvwrapper</a> makes virtualenv a pleasure to use by wrapping the command line API with a nicer CLI.</p>
|
|
<div class="highlight-python"><pre>$ pip install virtualenvwrapper</pre>
|
|
</div>
|
|
<p>Put this into your <cite>~/.bash_profile</cite> (Linux/Mac) file:</p>
|
|
<div class="highlight-python"><pre>$ export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'</pre>
|
|
</div>
|
|
<p>This will prevent your virtualenvs from relying on your (global) site packages directory, so that they are completely separate..</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="other-tools">
|
|
<h2>Other Tools<a class="headerlink" href="#other-tools" title="Permalink to this headline">¶</a></h2>
|
|
<div class="section" id="ipython">
|
|
<h3>IPython<a class="headerlink" href="#ipython" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://ipython.org/">IPython</a> provides a rich toolkit to help you make the most out of using Python interactively. Its main components are:</p>
|
|
<ul class="simple">
|
|
<li>Powerful Python shells (terminal- and Qt-based).</li>
|
|
<li>A web-based notebook with the same core features but support for rich media, text, code, mathematical expressions and inline plots.</li>
|
|
<li>Support for interactive data visualization and use of GUI toolkits.</li>
|
|
<li>Flexible, embeddable interpreters to load into your own projects.</li>
|
|
<li>Tools for high level and interactive parallel computing.</li>
|
|
</ul>
|
|
<div class="highlight-python"><pre>$ pip install ipython</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="bpython">
|
|
<h3>BPython<a class="headerlink" href="#bpython" title="Permalink to this headline">¶</a></h3>
|
|
<p><a class="reference external" href="http://bpython-interpreter.org/">bpython</a> is an alternative interface to the Python interpreter for Unix-like operating systems. It has the following features:</p>
|
|
<ul class="simple">
|
|
<li>In-line syntax highlighting.</li>
|
|
<li>Readline-like autocomplete with suggestions displayed as you type.</li>
|
|
<li>Expected parameter list for any Python function.</li>
|
|
<li>“Rewind” function to pop the last line of code from memory and re-evaluate.</li>
|
|
<li>Send entered code off to a pastebin.</li>
|
|
<li>Save entered code to a file.</li>
|
|
<li>Auto-indentation.</li>
|
|
<li>Python 3 support.</li>
|
|
</ul>
|
|
<div class="highlight-python"><pre>$ pip install bpython</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper"><h3><a href="http://python-guide.org">Python Guide</a></h3>
|
|
<p>
|
|
This opinionated guide exists to provide both novice and expert Python developers a best-practice handbook to the installation, configuration, and usage of Python on a daily basis.
|
|
</p>
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">Your Development Environment</a><ul>
|
|
<li><a class="reference internal" href="#text-editors">Text Editors</a><ul>
|
|
<li><a class="reference internal" href="#vim">VIM</a></li>
|
|
<li><a class="reference internal" href="#textmate">TextMate</a></li>
|
|
<li><a class="reference internal" href="#sublime-text">Sublime Text</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#ides">IDEs</a><ul>
|
|
<li><a class="reference internal" href="#pycharm-intellij-idea">PyCharm / IntelliJ IDEA</a></li>
|
|
<li><a class="reference internal" href="#eclipse">Eclipse</a></li>
|
|
<li><a class="reference internal" href="#komodo-ide">Komodo IDE</a></li>
|
|
<li><a class="reference internal" href="#spyder">Spyder</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#interpreter-tools">Interpreter Tools</a><ul>
|
|
<li><a class="reference internal" href="#virtualenv">virtualenv</a><ul>
|
|
<li><a class="reference internal" href="#other-notes">Other Notes</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#virtualenvwrapper">virtualenvwrapper</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#other-tools">Other Tools</a><ul>
|
|
<li><a class="reference internal" href="#ipython">IPython</a></li>
|
|
<li><a class="reference internal" href="#bpython">BPython</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<h3>Related Topics</h3>
|
|
<ul>
|
|
<li><a href="../index.html">Documentation overview</a><ul>
|
|
<li>Previous: <a href="../starting/install/linux.html" title="previous chapter">Linux</a></li>
|
|
<li>Next: <a href="virtualenvs.html" title="next chapter">Virtual Environments</a></li>
|
|
</ul></li>
|
|
</ul>
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../_sources/dev/env.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2012. A <a href="http://kennethreitz.com/pages/open-projects.html">Kenneth Reitz</a> Project. <a href="http://creativecommons.org/licenses/by-sa/3.0/"> Creative Commons Share-Alike 3.0</a>..
|
|
</div>
|
|
<a href="https://github.com/kennethreitz/python-guide" class="github">
|
|
<img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" />
|
|
</a>
|
|
|
|
<script type="text/javascript" src="//www.hellobar.com/hellobar.js"></script>
|
|
<script type="text/javascript">
|
|
new HelloBar(36402,48802);
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var _gaq2 = _gaq2 || [];
|
|
_gaq2.push(['_setAccount', 'UA-8742933-10']);
|
|
_gaq2.push(['_setDomainName', 'none']);
|
|
_gaq2.push(['_setAllowLinker', true]);
|
|
_gaq2.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga2 = document.createElement('script'); ga.type = 'text/javascript'; ga2.async = true;
|
|
ga2.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga2, s);
|
|
})();
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
(function() {
|
|
var t = document.createElement('script');
|
|
t.type = 'text/javascript';
|
|
t.async = true;
|
|
t.id = 'gauges-tracker';
|
|
t.setAttribute('data-site-id',
|
|
'4ddc1cfaf5a1f50fcc000001');
|
|
t.src = '//secure.gaug.es/track.js';
|
|
var s = document.getElementsByTagName('script')[0];
|
|
s.parentNode.insertBefore(t, s);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html> |