TensorCirucit c.draw() NameError - google-colaboratory

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.

Related

Unable to import required dependencies: numpy

I'm trying to build a visual dashboard in VS Code using dash. But I can't get past this error I'm getting:
Original error was: DLL load failed: The specified module could not be
found. File "C:\Users\ko14Z57\plots.py", line 1, in
import pandas as pd
Exception has occurred: ImportError Unable to import required
dependencies: numpy:
I'm using python 3.6.13 but I've tried this with python 3.9 and 3.8. I also tried installing\uninstalling numpy and pandas. I'm using Anaconda for my package management. Any help would be really appreciated!
in vscode from view>command palette write 'select your default profile' the select 'Command Prompt' or 'cmd.exe'
Assuming that Bas may be right, and you're missing the Microsoft C++ compiler. Try installing Microsoft's "C/C++ Extension Pack": https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack . You can find it in VSCode by clicking the extensions icon at the left side and searching "cpptools".
Since I'm using conda, I updated conda and then updated all of my packages and that worked.
conda update conda
conda update --all
Note: I'm on Python 3.9 on a Windows machine.
Probably unnecessary, but I also added the interpreter path to my launch.json file:
"python": "C:\\Users\\<username>\\Anaconda3\\python.exe"

How to fix matplotlib.pyplot problem in installed matplotlib in python

I am new in python and last month I have installed matplotlib module in my python and using that I have also done some codes successfully. But now suddenly I don't know why my matlpotlib module is not working. When I write "import matplotlib.pyplot as plt" it shows the error "ModuleNotFoundError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package" and the codes that was done before are also not working and showing the same error."import matplotlib" statement works properly in command prompt and IDLE. What am I suppose to do to solve this problem?

ModuleNotFoundError: No module named 'pandas.io' for json_normalize

Please read carefully. In my Python script I have the following:
import json
import pandas
from pandas.io.json import json_normalize
and it returns the following error:
from pandas.io.json import json_normalize ModuleNotFoundError: No
module named 'pandas.io'; 'pandas' is not a package
My steps:
I have uninstalled and installed Pandas
I have upgraded pip and pandas
I have installed io (pip install -U pandas.io)
I have installed data_reader and replaced the pandas.io.json part with that: from pandas_datareader import json_normalize
I have tried every solution I saw on stackoverflow and github and nothing worked. The only one I have not tried is installing Anaconda but it should work with what I tried before. Do you think it is a Windows setting things I must change?
PS: My Python version is 3.7.4
Try:
Go to ...\Lib\site-packages\pytrends on your local disk and open file request.py
Change
from pandas.io.json._normalize import nested_to_record
to
from pandas.io.json.normalize import nested_to_record
I had the same error, but it helped me.
also change
from pandas.io.json.normalize
to
from pandas.io.json._normalize
The cause of the problem was the fact that the python file had the name pandas. The filename was pandas.py. After renaming it, the code worked normally without errors.
i had same problem and i solve it b uninstalling extra python versions install on my windows.now i have only one python installed by anaconda,and everything is working perfectly

OpenAI Gym error running demo from intro page

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.

Cannot import Keras on Pycharm

I tried to code on Pycharm, but when I use from keras import backend as K it throws an import error like "cannot import name backend". But I can do it on terminal.
How can I fix this?
error
on terminal
Are you sure your PyCharm sees the same Python environment as what you are using in Terminal?
See if this possibly works for you:
use tensorflow on pyCharm
I got the same problem:
Check here:Pycharm cannot find installed packages: keras
After adding new package to project interpreter, you need to quit Pycharm and restart it again.
Use
from tensorflow.python.keras import backend as K
instead.