Here is a much simpler version of the Sieve of Eratosthenes:
def primes(n): # sieve of eratosthenes
ps, sieve = [], [True] * (n + 1)
for p in range(2, n + 1):
if sieve[p]:
ps.append(p)
for i in range(p * p, n + 1, p):
sieve[i] = False
return ps
There are ways to make that run faster without too much complexity. If you are interested in programming with prime numbers, I modestly recommend this essay at my blog.