flycheck: undefined name 'xrange'
<p>I am running <code>emacs24</code> and I'm new to emacs. I have some code in Python 2.7 that I am checking with <code>flycheck</code>.
When I check the syntax, I get:</p>

<pre><code>error F821 undefined name 'xrange' (python-flake8)
</code></pre>

<p>I understand that <code>xrange</code> is not in Python3, but here I'm on Python 2.7. I guess it's configured to run on Python 3, since also <code>raw_input</code> yields the same error.</p>

<p>How do I fix this?</p>

<p>I were struggling with same problem, and can recommend use my solution for that: <a href="https://github.com/rmuslimov/flycheck-local-flake8" rel="nofollow">https://github.com/rmuslimov/flycheck-local-flake8</a>. It's trivial - and it will force <strong>flycheck</strong> use proper <strong>flake8</strong> executable from your virtualenv.</p>

<p>I'd recommend add <code>setup.cfg</code> to each python project you work on. Flake8 has some environment variables which may be defined there. For example here is mine: </p>

<pre><code>[metadata]
name=fastttrace
version=release.5.9.0

[flake8]
exclude = tests/*, migrations/*
ignore = D100,D101,D102,D103,D205,D400,E731
import-order-style = google
max-complexity = 15
</code></pre>

<p>It allows you have separate flake8 rules per project and store them in repo, which is convenient way to share with other devs.</p>

python emacs flake8 flycheck