OpenAI Gym error running demo from intro page - google-colaboratory

I installed OpenAI Gym and attempted to run the getting-started cart-pole demo (https://gym.openai.com/docs/). (I'm running in a Colab notebook.)
import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample()) # take a random action
This doesn't learn, but it should display the cart and pole.
When I run it I get a warning and an error.
WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.
The error is triggered by env.render(). At the bottom of the Traceback is
Error occured while running `from pyglet.gl import *`
The original exception was:
ImportError: Library "GL" not found.
I had installed pyOpenGL with the following.
!pip install PyOpenGL PyOpenGL_accelerate
I'd appreciate help with both the warning and the error. Is there another GL library I should install?
Thanks.

Google Colab is run in the cloud. It can't send the graphic display back to your monitor.
You can try running it with local runtime.
https://research.google.com/colaboratory/local-runtimes.html

Do you get this window?
If yes then try to add this import:
import time
and this line of Code within the for-loop:
time.sleep(0.3)
Thing is that the pole runs out of view rather quick, so it seems like
the Environment did not run at all.

Related

ModuleNotFoundError: No module named 'seaborn' in spdyer

I recently installed spyder on my macbook (M1). I am getting module not found error when I tried to load seaborn.
Pl note
I am able to load the seaborn in jupyter notebook
Whey I change the python interpreter to the the one jupyter notebook is using (i.e. miniforge), I get following error
/Users/akbarboghani/miniforge3/bin/python: Error while finding module specification for 'spyder_kernels.console' (ModuleNotFoundError: No module named 'spyder_kernels')
Is there any setting I have missed? How do I resolve this
I tried changing preferences and restarted the spyder application. Checked for solution, did not find any.

TensorCirucit c.draw() NameError

I want to plot a circuit build with TensorCircuit using the draw method.
I am working on Google Colab and have pip installed qiskit.
Yet i get NameError: name 'QuantumCircuit' is not defined.
I have also tried from qiskit import QuantumCircuit but still i get the same error.
Executing the code on another JuypterHub works.
pip install qiskit
pip install pylatexenc
import numpy as np
from qiskit import *
Once you are done with above code you have to restart your runtime so that installed library come into force into your colab environment.
For restarting runtime:
Click on Runtime
Select Restart runtime
Select Run all
This help you to rectify your problem.

ImportError: cannot import name 'IEX_CLOUD_API_TOKEN' from 'secrets'

I'm facing the above error when I try to execute the following code:
from secrets import IEX_CLOUD_API_TOKEN
I tried using '.secrets' instead of 'secrets' but that gives the ModuleNotFoundError.
It's not a problem with the secrets library or anything of such kind.
It's just that after uploading secrets.py to the working directory, restart the kernel in your jupyter notebook.
Code shall run !!

Missing package to enable rendering OpenAI Gym in Colab

I'm attempting to render OpenAI Gym environments in Colab via a Mac using the StarAI code referenced in previous questions on this topic. However, it fails. The key error (at least the first error) is shown in full below, but the import part seems to be "Please install xdpyinfo!"
PyPI doesn't have xdpyinfo. What is it and how do I install it?
Full error message:
482780428160 abstractdisplay.py:151] xdpyinfo was not found, X start can not be checked! Please install xdpyinfo!
I've seen the same error, and solved it by installing x11-utils package which includes xdpyinfo command.
!apt-get install x11-utils

NameError: name 'python' is not defined when importing part of tensorflow's deeplab module

Thanks to this github issue, I realise that I shouldn't try to reload tensorflow, because I get this error:
del python
NameError: name 'python' is not defined
when I do
import tensorflow
from deeplab import common
In case it's relevant, import deeplab works fine.
I saw elsewhere that it's probably the IPython session in spyder that is keeping a tensorflow session open. So I closed spyder - but launching python in the shell gave me the same issue. ps -ef | grep -E 'py|tensorflow|tensorboard|tf' came up empty. What could still be hanging around and causing tensorflow to try a reload, rather than a fresh load?
I understand that the issue around reloading tensorflow will not be resolved. How do I make sure that I have cleared everything from my previous runs so that it will be a fresh load rather than a reload?
Edit: even after restarting the computer I get the same error. Even if the first thing I do is open a python console and type from deeplab import common. That means the original title to my question is probably wrong, so I have changed it.