cImage python module error - python

I'm writing a function to convert and display an image to negative, when i call the function i get this error message:
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Librophyton/Procdeimagenes/test.py",line 32, in <module>
makeNegative(dude)
File "C:\Python34\lib\ImageProcess.py", line 16, in makeNegative
old = FileImage(imageFile)
File "C:\Python34\lib\cImage.py", line 398, in __init__
super(FileImage, self).__init__(fname = thefile)
File "C:\Python34\lib\cImage.py", line 241, in __init__
self.loadImage(fname)
File "C:\Python34\lib\cImage.py", line 270, in loadTkImage
sufstart = fname.rfind('.')
AttributeError: 'FileImage' object has no attribute 'rfind'
Here is the function:
def makeNegative(imageFile):
window = ImageWin("Proceso de imagen", 1000-100, 900)
old = FileImage(imageFile)
old.draw(window)
window.exitOnClick()
w = old.getWidth()
h = old.getHeight()
new = EmptyImage(w,h)
for row in range(h):
for col in range(w):
pixelviejo = old.getPixel(col,row)
pixelnuevo = pixelNeg(pixelviejo)
new.setPixel(col, row, pixelnuevo)
new.setPosition(w+1, 0)
new.draw(window)
window.exitOnClick()
And here is the funciton call:
dude = FileImage("factores_de_conversion.gif" )
makeNegative(dude)
Any idea how to solve this? or how should i modify the module?

Related

Expected type 'Canvas', got 'int' instead

from tkinter import *
window = Tk()
window.title('Pomodoro timer')
window.config(padx=100, pady=50)
canvas = Canvas(width=200, height=224)
tomato_img = PhotoImage(file="C:/vscode/tomato.png")
canvas.create_image(102, 112, image=tomato_img)
Canvas.create_text(102, 112, text='00:00')
canvas.pack()
window.mainloop()
This is the code that I'm working on
when I'm trying to add two integers for x and y co-ordinates to the Canvas.create_text function, it gives me this error
Traceback (most recent call last):
File "C:\pycharm and thonny\pythonProject1\main.py", line 26, in <module>
Canvas.create_text(102, 112, text='00:00')
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2810, in create_text
return self._create('text', args, kw)
AttributeError: 'int' object has no attribute '_create'

mcpi-e. error when getting coordinates. mc.player.getPos()

Code:
from mcpi_e.minecraft import Minecraft
mc = Minecraft.create('127.0.0.1', 4711)
pos = mc.player.getPos()
When trying to get coordinates.
mc.player.getPos()
an error pops up
Error:
Traceback (most recent call last):
File "C:\Users\merka\Desktop\pyt minecraft\buy.py", line 23, in <module>
pos = mc.player.getPos()
File "C:\Users\merka\AppData\Local\Programs\Python\Python39\lib\site-packages\mcpi_e\minecraft.py", line 230, in getPos
return CmdPositioner.getPos(self, self.playerId)
File "C:\Users\merka\AppData\Local\Programs\Python\Python39\lib\site-packages\mcpi_e\minecraft.py", line 50, in getPos
s = self.conn.sendReceive(self.pkg + b".getPos", id)
File "C:\Users\merka\AppData\Local\Programs\Python\Python39\lib\site-packages\mcpi_e\connection.py", line 103, in sendReceive
return self.receive()
File "C:\Users\merka\AppData\Local\Programs\Python\Python39\lib\site-packages\mcpi_e\connection.py", line 97, in receive
raise RequestError("%s failed"%self.lastSent.strip())
mcpi_e.connection.RequestError: b'entity.getPos()' failed
Process finished with exit code 1
what can be done?
mc = Minecraft.create('127.0.0.1', 4711, "merka")
I should have added a nickname

'NoneType' Object is not Subscriptable on deap expr func call

I'm aware that there are other questions with the same name, but they're all about indexing and I'm getting this error when trying to invoke func(r_curr). I've already checked and func is not NoneType after assignment, it is <function <lambda> at 0x000001BB1E91E510>.
def eval_symb_reg(individual, points):
global X
global y
global size
func = toolbox.compile(expr=individual)
predict = []
for i in range(X.shape[0]):
total = 0
for j in range(size):
r_curr = X[i][j*size:(j+1)*size]
result = func(r_curr)
total += result[0]
predict.append(total)
error = np.sum((np.array(predict) - y) ** 2)
return [1 / (error / X.shape[0])]
Stack trace:
Traceback (most recent call last):
File "symbreg.py", line 298, in <module>
main()
File "symbreg.py", line 265, in main
halloffame=hof, verbose=True)
File "C:\Users\<myuser>\AppData\Local\Programs\Python\Python36\lib\site-packages\deap\algorithms.py", line 151, in eaSimple
for ind, fit in zip(invalid_ind, fitnesses):
File "symbreg.py", line 198, in eval_symb_reg
result = func(r_curr)
File "<string>", line 1, in <lambda>
TypeError: 'NoneType' object is not subscriptable

Large number error with the Python Turtle

I am reading a set of coordinates from a file to produce a shape in the Python Turtle. After reading reading in the coordinates, I have written a for loop that goes through the list of coords and draws them. However, upon running with a correct file name, I get this error:
Traceback (most recent call last):
File "C:\Users\06113\Desktop\My Stuff\Python Saves\Vec Draw\Vec Draw.py", line 55, in <module>
t.goto(cs)
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 1774, in goto
self._goto(Vec2D(*x))
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 3195, in _goto
self._update() #count=True)
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2660, in _update
self._update_data()
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 2650, in _update_data
self.screen._drawline(self.currentLineItem, self.currentLine,
File "C:\Users\06113\AppData\Local\Programs\Python\Python38-32\lib\turtle.py", line 543, in _drawline
cl.append(x * self.xscale)
TypeError: can't multiply sequence by non-int of type 'float'
Is there any way at all that I could fix this in MY file? I would rather not go into the turtle module where I could easily mess something up.
The code for this section in my file is:
t = turtle.Turtle(visible=False)
t.speed(0)
for i in range(0, len(coord_list), 2):
if i == 0 and i+1 == 1:
fcs = (coord_list[i], coord_list[i+1])
t.pu()
t.goto(fcs)
t.pd()
pass
else:
cs = (coord_list[i], coord_list[i+1])
t.goto(cs)
cs = None
pass
pass
t.goto(fcs)
print("Vector image drawn.")

Problem with scapy summary function in python

I've imported the scapy module in my python code (arp-spoofer) and when i use the packet.show()/packet.summary() function the terminal return me this error:
Error:
Traceback (most recent call last):
File "arp-spoofer.py", line 10, in <module>
print(packet.show())
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/packet.py", line 1261, in show
return self._show_or_dump(dump, indent, lvl, label_lvl)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/packet.py", line 1235, in _show_or_dump
reprval = f.i2repr(self, fvalue)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/fields.py", line 376, in i2repr
return fld.i2repr(pkt, val)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/fields.py", line 502, in i2repr
x = self.i2h(pkt, x)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/layers/l2.py", line 136, in i2h
iff = self.getif(pkt)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/layers/l2.py", line 132, in <lambda>
self.getif = (lambda pkt: pkt.route()[0]) if getif is None else getif
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/layers/l2.py", line 400, in route
fld, dst = fld._find_fld_pkt_val(self, dst)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/fields.py", line 313, in _find_fld_pkt_val
if val == dflts_pkt[self.name] and self.name not in pkt.fields:
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/base_classes.py", line 133, in __eq__
p2, nm2 = self._parse_net(other)
File "/home/baloo/.local/lib/python3.7/site-packages/scapy/base_classes.py", line 99, in _parse_net
tmp = net.split('/') + ["32"]
AttributeError: 'NoneType' object has no attribute 'split'
Code:
import scapy.all as scapy
victim_ip = ""
victim_mac_address = ""
router_ip = ""
packet = scapy.ARP(op=2, pdst=victim_ip, hwdst=victim_mac_address, psrc=router_ip)
print(packet.show())
print(packet.summary())
You need the IPs to be valid.
If you don't want to set them yourself, don't specify them and Scapy will take the default.

Categories