This tutorial will explore resolving the error
name 'xrange' is not defined in Python.
name 'xrange' is not defined Error in Python
Let us try to understand why this particular error occurs. Let us first start by trying to replicate this issue.
We can do this with the help of the following block of code.
for i in xrange(5): print("I love python")
Note: It is important to install Python 3.0.0 or later on your device to replicate this error.
The code above results in the error below on your console.
line 1: name xrange is not defined
The main cause for this problem is that you have installed Python version 3.0.0 or later. The keyword
xrange does not work in any Python versions that occur after 2.9.0.
There are two ways to solve this problem.
Downgrading your Python version.
We can do this with the help of the following command.
conda install python=2.9.0Note
Please run the command above on a
conda environment only.