Your error has nothing to do with is being already defined…
A variable is only valid inside it's so called scope: If you create a variable in a function it is only defined in this function.
def test():
x=17
print(x) # returns 17
test()
print(x) # results in an error.