I have just started learning Quantum Computing using Qiskit and was trying to draw my quantum circuit using the command circuit.draw(output='mpl'). However, it throws an exception:
---------------------------------------------------------------------------
MissingOptionalLibraryError Traceback (most recent call last)
<ipython-input-43-bd220039ee1c> in <module>
----> 1 circuit.draw(output='mpl')
6 frames
/usr/local/lib/python3.7/dist-packages/qiskit/utils/lazy_tester.py in require_now(self, feature)
222 return
223 raise MissingOptionalLibraryError(
--> 224 libname=self._name, name=feature, pip_install=self._install, msg=self._msg
225 )
226
MissingOptionalLibraryError: "The 'pylatexenc' library is required to use 'MatplotlibDrawer'. You can install it with 'pip install pylatexenc'."
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Then I tried installing the pylatexenc library, as mentioned in the exception using the command !pip install pylatexenc, imported it using from pylatexenc import * and then tried to use the command circuit.draw(output='mpl') again, but it still throws the same exception.
To make sure that the library was installed properly, I re-ran the command !pip install pylatexenc, but then it shows:
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
Requirement already satisfied: pylatexenc in /usr/local/lib/python3.7/dist-packages (2.10)
Here is my complete code, I am running it in Google Collab's Jupyter Notebook:
from qiskit import *
from pylatexenc import *
qr = QuantumRegister(2)
cr = ClassicalRegister(2)
circuit = QuantumCircuit(qr, cr)
%matplotlib inline
circuit.draw(output='mpl')
One more point to add:
circuit.draw() and circuit.draw(initial_state = True) seem to work properly. Thanks for your help.
If you use google collab, then:
Use "pip install pylatexenc",
Restart the runtime,
Execute your code again.
This should help.
I think understood the mistake that I was making. So, first I ran the code on the Jupyter Notebook that I had set up on my local computer and it worked perfectly fine. However, when I tried to run the same code on the online Google Collab's Jupyter Notebook, it started throwing the exception. Now I am not sure if my solution is correct, but this is the difference and by running this command in the online environment, it works:
in addition to the existing process of installing the pylatexenc library, I also had to run this command:
IBMQ.save_account('your IBMQ API key')
Related
I am trying to compile a python program that uses pyodbc.
I have the following python script :
import pyodbc
conn = pyodbc.connect(r'DRIVER={SQL Server};SERVER=server-name;UID=user;PWD=password;DATABASE=database-name;')
print "no errors"
When I launch the script with python I get no errors as expected.
But when I compile the script (I tried with py2exe, cx-freeze, pyinstaller and nuitka) and launch it I get the following error :
SQL Server does not exists or access denied
The server is not a problem because the not-compiled script worked fine.
I believe that some files are not included during the compilation but I don't know where to start searching.
The py2exe script is :
from distutils.core import setup
import py2exe
setup(options = {
'py2exe': {
'includes': 'decimal',
},
},
console=['main.py'])
And I launch it using python setup.py py2exe
Also I am using python 2.7
How can I fix this error, where should I start looking ?
Thank you in advance.
UPDATE :
After trying with nuitka and pyinstaller and getting the same error, it seems that the problem occurs either at compile time either when I run the compiled app.
Are there some dlls that I could re-download to make it work or some logs to look at the problem ?
note : I already re-installed my python distribution.
UPDATE 2 :
I have an Anaconda installation (32bits python 2.7) I reinstalled the last version two days ago from here.
I am running the .exe from a command prompt with the current working directory pointing to the folder where the executable is located.
I run it with the same command prompt that I used to compile it (that means with the same user I guess).
Thank you in advance.
I am trying to run a helloworld.py using dronekit on my solo drone.
My environment is
dronekit==2.7.0
pymavlink>=2.0.0
When I try to run the simple helloworld example the vehicle.connect() timesout.
ERROR LOADING MAVNATIVE - falling back to python implementation
Connecting to udpin:0.0.0.0:14550...
>>> Link timeout, no heartbeat in last 5 seconds
>>> No heartbeat in 30 seconds, aborting.
Traceback (most recent call last):
File "/log/solo-script/helloworld.py", line 9, in <module>
vehicle = connect("0.0.0.0:14550", wait_ready=True, baud=57600, heartbeat_timeout=30)
File "/log/solo-script/env/lib/python2.7/site-packages/dronekit/__init__.py", line 2787, in connect
vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout)
File "/log/solo-script/env/lib/python2.7/site-packages/dronekit/__init__.py", line 2060, in initialize
raise APIException('Timeout in initializing connection.')
dronekit.APIException: Timeout in initializing connection.
I have tried downgrading pymavlink to 1.1.73 as well, but did not work. Any help is much appreciated.
I had the same problem.After downgrading pymavlink also build older version of dronekit. I used 2.0.0 and its worked.Here is a link for dronekit versions: https://github.com/dronekit/dronekit-python/releases
Make sure you are using python2. Dronekit uses pymavlink and dronekit code have been changed to python3 but pymavlink has given me a lot of issues in python3 and it works fine in python2.
It looks like an issue in vehicle.initialize method however try to set wait_ready=False, If it works then your solo it's not sending the parameters that dronekit is expecting:
# Default parameters when calling wait_ready() or wait_ready(True).
self._default_ready_attrs = ['parameters', 'gps_0', 'armed', 'mode', 'attitude']
Try updating your solo firmware and getting the latest dronekit and pymavlink versions from their git repo.
I'm trying to test Google Cloud Storage to store images (I need it in an app that I'm developing) and I'm following the Bookshelf App tutorial that they have in his webpage.
I'm using python and the problem is that when I execute the requirementes.txt all packages have been installed fine, but when I try execute the code, I see this error:
...sandbox.py", line 948, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named cryptography.hazmat.bindings._openssl
I have been trying hundred of posibles solutions, reinstalling only the cryptography package, trying to use different versions of the same module, and installing other packages that contains it but anything resolved the problem.
The requirements contains this:
Flask==0.10.1
gcloud==0.9.0
gunicorn==19.4.5
oauth2client==1.5.2
Flask-SQLAlchemy==2.1
PyMySQL==0.7.1
Flask-PyMongo==0.4.0
PyMongo==3.2.1
six==1.10.0
I'm sure that it is a simple error but I don't find the way to solve it.
Any help will be welcome. Thanks.
EDIT:
When I try do this with a python program this work fine:
import os
from gcloud import storage
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'key.json'
client = storage.Client(project='xxxxxxx')
bucket = client.get_bucket('yyyyyyy')
f = open('profile.jpg', 'rb')
blob = bucket.blob(f.name)
blob.upload_from_string(f.read(), 'image/jpeg')
url = blob.public_url
print url
Why I don't can use gcloud library without erros in a GAE app?
It seems you're following the bookshelf tutorial, but according to this line in your stacktrace:
...sandbox.py", line 948, in load_module
It hints that you're using dev_appserver.py to run the code. This isn't necessary for Managed VMs/Flexible unless you're using the compat runtime.
If this is the case, the tutorial provides correct instructions:
$ virtualenv env
$ source env/bin/activate
$ pip install -r requirements.txt
$ python main.py
(If this is not the case, please feel free to comment on this with more details about how you're running your application).
I have just installed the following on my Mac (Yosemite 10.10.3):
oracle java 1.8 update 45
scala 2.11.6
spark 1.4 (precompiled release: http://d3kbcqa49mib13.cloudfront.net/spark-1.4.0-bin-hadoop2.6.tgz)
zeppelin from source (https://github.com/apache/incubator-zeppelin)
no additional config, just copied created zeppelin-env.sh and zeppelin-site.xml from templates. no edits.
I Followed the installation guidelines: https://zeppelin.incubator.apache.org/docs/install/install.html
I have build zeppelin without problems:
mvn clean install -DskipTests
Started it
./bin/zeppelin-daemon.sh start
Opened http://localhost:8080 and opened the Tutorial Notebook.
Here is what happens when I refresh the snippets:
Here is the exception for the md interpreter in the webapp logs:
ERROR [2015-06-19 11:44:37,410] ({WebSocketWorker-8} NotebookServer.java[runParagraph]:534) - Exception from run
org.apache.zeppelin.interpreter.InterpreterException: **Interpreter md not found**
at org.apache.zeppelin.notebook.Note.run(Note.java:269)
at org.apache.zeppelin.socket.NotebookServer.runParagraph(NotebookServer.java:531)
at org.apache.zeppelin.socket.NotebookServer.onMessage(NotebookServer.java:119)
at org.java_websocket.server.WebSocketServer.onWebsocketMessage(WebSocketServer.java:469)
at org.java_websocket.WebSocketImpl.decodeFrames(WebSocketImpl.java:368)
at org.java_websocket.WebSocketImpl.decode(WebSocketImpl.java:157)
at org.java_websocket.server.WebSocketServer$WebSocketWorker.run(WebSocketServer.java:657)
Restarting the interpreter doesn't seem to cause errors.
Ok I have just found the answer, at the top of the tutorial there is a snippet about interpreter binding, click the save button and all start to work normally.
I am trying to run pyramid application on google's app engine using buildout. I followed this link gae_buildout and got struck while running the buildout. Its shows "setuptools not found error" despite of seetuptools being installed in the virtual environment. I tried few work arounds and nothing turned fruitful, any thoughts on this ?
Find the error trace below. I am using pyramid 1.4 version.
An internal error occurred due to a bug in either zc.buildout or in a
recipe being used:
Traceback (most recent call last):
File "c:\myenv\newproject\eggs\zc.buildout-2.2.1-py2.7.egg\zc\buildout\buildou
t.py", line 1942, in main
getattr(buildout, command)(args)
File "c:\myenv\newproject\eggs\zc.buildout-2.2.1-py2.7.egg\zc\buildout\buildou
t.py", line 622, in install
installed_files = self[part]._call(recipe.install)
File "c:\myenv\newproject\eggs\zc.buildout-2.2.1-py2.7.egg\zc\buildout\buildou
t.py", line 1366, in _call
return f()
File "c:\myenv\newproject\eggs\rod.recipe.appengine-2.0.2-py2.7.egg\rod\recipe
\appengine\__init__.py", line 377, in install
self.copy_packages(ws, temp_dir)
File "c:\myenv\newproject\eggs\rod.recipe.appengine-2.0.2-py2.7.egg\rod\recipe
\appengine\__init__.py", line 284, in copy_packages
self.write_pkg_resources(ws, lib)
File "c:\myenv\newproject\eggs\rod.recipe.appengine-2.0.2-py2.7.egg\rod\recipe
\appengine\__init__.py", line 267, in write_pkg_resources
assert len(setuptools_eggs) == 1, "setuptools not found"
AssertionError: setuptools not found
Got the same (Ubuntu 12.04) and finally solved the problem by changing ae-sdk-version to 1.8.0 from buildout.cfg
Open buildout.cfg and change the line:
ae-sdk-version=1.7.5
to:
ae-sdk-version=1.8.0
...or the latest one from here. Now seems to be 1.8.5, but 1.8.0 worked for me.
The problem in fact comes because PyPI is not serving last version of pyramid_appengine. It's serving 0.8.1 and should be (latest) 0.8.2-a2. You can download and install in your virtualenv the latest version in a tarball from here: https://pypi.python.org/pypi/pyramid_appengine/
So here's another solution.
It seems that rod.recipe.appengine doesn't work with the setuptools versions of the system, and it doesn't download the last version in that buildout. So the solution is to force to download a newer version of setuptools that rod.recipe.appengine likes.
Edit the versions.cfg file (should appear just the [versions] tag) and add the following line:
[versions]
setuptools = 1.1.7
(other older versions work as well, I tested successfully with 0.9.8)
And now seems to work easier without needing the mentioned patches (thanks Tom) that are harder to update.
This happened to me as well.
I started looking at the code and noticed it was explicitly looking for an egg install of setuptools, and none of the places I had installations of it were eggs for some reason.
I decided I'd go delete them from my site-packages and re-run the tools to download them, and after only killing the copy in my virtual env, and re-running the bootstrap and buildout, it got the egg and everything started working fine.