You have to downgrade pyglet 3 to pyglet 1.2.4.just type:
pip install pyglet==1.2.4 in your anaconda prompt. Afterwards you might have to restart your spyder ide.
I would add
env.close() to your code, otherwise you will have troubles closing the window.
if you are new to python/ML/DL have a look at "sentdex" on youtube. imo very good content to start with. (he uses TFlearn in his gym tutorial) But since tensorflow 1.4 has Keras included, i would suggest to use keras high lvl API for your neural network.
good luck and stay deep
if someone has a good gym documentation, feel free to share it.