Hey Guys I written some code to make a simple hut using turtle and shapes in python but when i am importing the shapes then it is showing me error this is the error
here is my code
import turtle
from shapes import *
# naming the turtle
pen = turtle.Turtle()
# setting up turtle
pen.speed(100)
pen.color(0,0,0)
wn = turtle.Screen()
wn.color(66,202,244)
#start drawing
drawWindow(pen,-95,15,"square")
drawHouse(pen)
drawDoor(pen,-25,-20)
drawBush(pen,120,35)
drawWindow(pen,-10,100,"circle")
drawFence(pen)
drawPath(pen)
drawWindow(pen,-95,100,"square")
drawGrass(pen)
drawCloud(pen,75,160)
drawWindow(pen,75,15,"square")
drawSun(pen,-200,160,70)
drawWindow(pen,180,150,"square")
then i read a solution for this to install "pysal" but when I am installing pysal(pip install pysal) from cmd then it is also showing this error while installing pysal
please resolve it.
The error says no module is named shapes to solve that you need to pip install shapes
There is the code in shapes/__init__.py:
from Shape import Shape
The code works under Python 2 and doesn't work under Python 3. For Python 3 it must be either
from shapes.Shape import Shape
or
from .Shape import Shape
The same problem with other relative imports. The bottom line: the package shapes is Python2-only. Please report the problem or even better send a pull-request to fix it.
Related
I am working through the Qiskit tutorial textbook, and in Section 1.4 ('Single Qubit Gates'), I can't seem to plot vectors on the Bloch Sphere.
I am using Google Colab and am importing as:
!pip install qiskit
!pip install qiskit[visualization]
from qiskit import QuantumCircuit, assemble, Aer
from math import pi, sqrt
from qiskit.visualization import plot_bloch_multivector, plot_histogram
sim = Aer.get_backend('aer_simulator')
and then the following code is taken directly from the textbook:
qc = QuantumCircuit(1)
qc.x(0)
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)
Yet doing this gives the error: " 'Arrow3D' object has no attribute '_path2d' ". Any help would be greatly appreciated.
Edit: Adding a line plt.show() no longer brings up an error message, but still no image shows.
i had this same issue and upgrading matplotlib (to 3.5.1) fixed it for me
I'm having the same problem. One workaround that I found is to use the Kaleidoscope package link. It's a visualization package developed by someone working at IBM. I actually like this as it uses Plotly for the figures.
import kaleidoscope.qiskit
from kaleidoscope import bloch_sphere
Then you can just type
bloch_sphere(state)
Hi I am a new to computer visionand stackoverflow and I have a problem with my python 3 program on Windows,as the cv2.findContours() function returns 2 instead of three values as in the documentation. I passed 2 values for return to solve the bug,the type of the first(image) is a list and that of the second (cnts)is an int32 but none of them is abled to be used in cv2.drawContours() without bugging here I use image as parameter in because it is the only list returned so I guess it is the contours list cv2.drawContours().So here is the code:
#This is the program for a document scanner so as to extract a document
#from any image and apply perspective transform to show it as final result
import numpy as np
import cv2
import imutils
from matplotlib import pyplot as plt
cap=cv2.VideoCapture(0)
ret,img=cap.read()
img1=img.copy()
cv2.imshow('Image',img1)
img1=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
img1=cv2.bilateralFilter(img1,7,17,17)
img1=cv2.Canny(img1,30,200)
image,cnts=cv2.findContours(img1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#cnts=np.asarray(cnts,dtype='uint8')
cnts=np.array(cnts)
cv2.imshow('Edge',img1)
print('cnts var data type',cnts.dtype)
#print("Hi")
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
Here is the python idle shell result appearing now:
cnts var data type is int32
Traceback (most recent call last):
File "D:\PyCharm Projects\Test_1_docscanner.py", line 20, in <module>
img=cv2.drawContours(img,[image],-1,(255,255,0),3)
TypeError: contours is not a numpy array, neither a scalar
I got it working finally,the following I did:
First I had previously messed up with most of my environmental variables haven suppressed some system variables. So I with help of a friend I retrieved as much as I could and deleted those I had stupidly ignorantly created.
Secondly I uninstalled all other python versions(at least I tried) though it seems that I still see their icons around(they seem to be "undeletable") and even the one I was using(Python3.7.3). I then install Python 3.7.4.
Thirdly,and that must be the answer is that I added this line cnts=imutils.grab_contours(cnts) before the cv2.drawContours() functions. Getting this from imutils package from Adrian Rosebrock github. my code now works because of that line which helps to parse the contours for whatever cv2.drawContours() opencv version you are using thereby avoiding conflicts of versions originating from cv2.findContours() function used prior to cv2.drawContours().
In conclusion I tried imutils.grab_contours() previously to these changes on my python3.7.3 but it did not work. But I believe above all the combination of "cnts=imutils.grab_contours(cnts)" and the update to Python3.7.4,is what solved the issue.
Hope this is helpful
I am a Python newbie currently looking into Crash Course Ai #5 How to Make an AI read your handwriting (LAB).
Running Step 1.2 gives me *NameError: name 'extract_training_samples' is not defined.
Tried so far: 1) updated pip version to 20.0.2 and installed emnist python package
2) tried an additional line of code: from emnist import extract_training_samples but got a ModuleNotFound error.
Feedback appreciated!
OK, very simple solution!
You just forgot the "s".
I find myself running into that problem all the time when coding. Whenever I run into a Name Error, the first thing I do is check my spelling!
your code:
x, y = extract_training_sample('letters')
the code on the website:
extract_training_samples('letters')
Cheers,
I'm currently working on a script that creates a tray icon that allows the user to adjust screen brightness through menu options. The source code, written in python 3.6.8, can be found as a paste HERE. There seems to be an error message coming up when trying to select one of the brightness options, seen HERE. I did some reading and found that the error I'm getting (0x8004100c) refers to a feature or operation not being supported. Are there any workarounds available for this?
Thank you in advance.
code: https://pastebin.com/sLbyE9yb
error: https://pastebin.com/Xs7wHk73
WMI error reference: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
gist: https://gist.github.com/imri0t/12e768e3d7e08734b85ae532d56090e1
(also if anyone can let me know if there's a way to keep the script from dying after an action is made it would be appreciated)
modules needed: pip install infi.systray / pip install wmi
code snip that I believe produces the error:
from infi.systray import SysTrayIcon
import wmi
def brightness_50(systray):
'''brightness: 50%'''
b = 50
c = wmi.WMI(namespace='root\\wmi')
br = c.WmiMonitorBrightnessMethods()[0]
br.WmiSetBrightness(3, b) #b will be a precentage / 100
menu = (("brightness: 100%", None, brightness_50))
systray = SysTrayIcon("icon.ico", "brightness", menu)
systray.start()
Using Python 2.7.9 with GDAL 1.11.1, with miniconda for package management --
Performing this a simple reprojection of a coordinate point causes the error described below.
I am relatively new to GDAL, so I checked to see if the code from the Python GDAL/OGR 1.0 Cookbook produces the same issue, and it does:
from osgeo import ogr
from osgeo import osr
source = osr.SpatialReference()
source.ImportFromEPSG(2927)
target = osr.SpatialReference()
target.ImportFromEPSG(4326)
transform = osr.CoordinateTransformation(source, target)
point = ogr.CreateGeometryFromWkt("POINT (1120351.57 741921.42)")
point.Transform(transform)
print point.ExportToWkt()
This is the error:
/opt/miniconda/envs/pygeo/lib/python2.7/site-packages/osgeo/ogr.pyc in Transform(self, *args)
4880 OGRERR_NONE on success or an error code.
4881 """
-> 4882 return _ogr.Geometry_Transform(self, *args)
4883
4884 def GetSpatialReference(self, *args):
TypeError: in method 'Geometry_Transform', argument 2 of type 'OSRCoordinateTransformationShadow *'
CoordinateTransform is a proxy for the C++ OSRCoordinateTransformationShadow class, generated by SWIG.
Per the source code for osgeo.ogr.Geometry (what Point is), the correct types were passed to the Transform method.
Best guess: Could this be caused by using a version of _ogr that is too old, and so the implementation of _ogr.Geometry_Transform(self, *args) is expecting a different?
_ogr is another SWIG-generated proxy, I'm guessing for the OGR class?
What everyone new to GDAL must learn: assign an error handler. (example: http://pcjericks.github.io/py-gdalogr-cookbook/gdal_general.html#install-gdal-ogr-error-handler)
With an error handler assigned, the output includes the explanation for the error. In this case, it was: "Unable to load PROJ.4 library (libproj.so), creation of OGRCoordinateTransformation failed."
Hopefully, imparting the knowledge of enabling GDAL error handling will help others who may stumble upon this very issue.
Similar information can be found on a rasterio FAQ and in unable to load "gcs.csv" file in gdal.
I encountered this problem when running GDAL transformations in my Anaconda3 QGIS environment. The problem is that the coordinate system informations were not loading through the GDAL_DATA environment variable.
To remedy, locate where the directory containing gcs.csv exists within your system (potentially ".../Library/share/gdal"). Add this to your environment prior to importing GDAL & other dependents.
import os
os.environ['GDAL_DATA'] = r'/path/to/dir/'
With help of the answer of jeremy that GDAL fails to load its information, I just edited the code to specify directly the PROJ.4 parameters from the EPSG webside and it runs
#target.ImportFromEPSG(4326)
target.ImportFromProj4('+proj=longlat +datum=WGS84 +no_defs')