Hi guys,
I am devoloping with Pillow and (Tkinter,BmpIma gePlugin,cStrin gIO,subprocess, ctypes,re .. n) modules
I am using this way when if this situation show me AttributeError
I solve this code line with try-except -
try:
-
from PIL import *
-
except AttributeError: #module has no attribute ImageN
-
import Image
-
import ImageDraw
-
import ImageFont
-
My orginal code part -
class capsGen(object):
-
def __init__(self):
-
pass
-
-
def videoGen(self,path):
-
iv = InputVideoStream()
-
iv.open(path)
-
self.videoHead(path)
-
print self.topDuration
-
frameDiff = list(enumerate(iv.readframe())) #bmp -> [io][1]
-
self.totalFrame = frameDiff [-1][0]
-
#16 imgs
-
self.genImgs = []
-
curImg = 0
-
while True:
-
if curImg < 16:
-
self.genImgs.append(randint(1,self.totalFrame))
-
curImg = curImg + 1
-
else:
-
break
-
-
-
try:
-
src = PIL.Image.open("src.png")
-
ciz = PIL.ImageDraw.draw(src)
-
ft = PIL.ImageFont.truetype("arial.ttf",32)
-
ciz.text((190,15),self.fileName,font=ft) #fileName
-
src.save("1.png")
-
-
-
#print frameDiff[5][0]
-
for i in self.genImgs:
-
imj = PIL.Image.open(StringIO.StringIO(frameDiff[i][1])) #base io -> [capsNo][1]
-
imj.save("%s.png"%i)
-
except NameError:
-
src = Image.open("src.png")
-
ciz = ImageDraw.draw(src)
-
ft = ImageFont.truetype("arial.ttf",32)
-
ciz.text((190,15),self.fileName,font=ft) #fileName
-
src.save("1.png")
-
-
-
#print frameDiff[5][0]
-
for i in self.genImgs:
-
imj = Image.open(StringIO.StringIO(frameDiff[i][1])) #base -> [io][1]
-
imj.save("%s.png"%i)
-
-
-
My error, -
Traceback (most recent call last):
-
File "o.py", line 275, in (module)
-
run = capsGen()
-
File "o.py", line 42, in __init__
-
self.videoGen() #for developers
-
File "o.py", line 157, in videoGen
-
ciz = ImageDraw.draw(src)
-
NameError: global name 'ImageDraw' is not defined
-
But I installed Pillow module and I create empty python file in import PIL or Image..N module are working. Its isn't just working on the my_project (o.py)
Than you for interest.
Good works.
2 9449 dwblas 626
Recognized Expert Contributor
It could be many things, including permission problems with the image file. Try the following code ("chairs.png ", from Manning's book, is attached for testing). Substitute your file name(s) and see what works and what does not, and then you can hopefully adapt to your program. - import Image, ImageDraw
-
-
image_name="chairs.png"
-
im = Image.open(image_name)
-
draw = ImageDraw.Draw(im)
-
draw.line((0, 0) + im.size, fill=255)
-
draw.line((0, im.size[1], im.size[0], 0), fill=128)
-
-
im.show()
Hello @dwblas,
I tried reference name like to you said to me.
And, I did invalid move, I forget Tkinter module in Image attribute
I changed this from Tkinter import *
And, my project file in some .open functions, I changed to these names.
Thank for interest.
Good works.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: NetKev |
last post by:
I added a function 'warn_Admin' and defined it just before another
function 'process_log'. 'process_log' calls this warn_Admin' function.
However, when it gets called i get the following error every time:
---
Traceback (most recent call last):
File "/usr/bin/denyhosts.py", line 202, in ?
first_time, noemail, daemon)
File...
|
by: Evan |
last post by:
Hi
I have a short script that makes 2 calls to methods in another script
as follows:
import canPlaces as canp
callOne=canp.addMe(3,5)
callTwo=canp.estocStn()
|
by: pythonnewb |
last post by:
I am fairly new to programming but have some very basic Java background. I am just learning python and tried to make a module that would allow me to create a file containing an address book. I was planning to then create a program to detect input and use this module, but I am hung up. I have constructed the code that I thought would work (though...
|
by: Lalit |
last post by:
Hi
I am very new to web development. I started with Pylons. I am using
http://www.rexx.com/~dkuhlman/pylons_quick_site.html as reference to
create a sample web page using pylons.
I got stuck up at step 4.3 i.e when modifying controller to "return
Response('<p>firstapp default</p>')"
I am getting error of <type 'exceptions.NameError'>:...
|
by: Netwatcher |
last post by:
im try to activate the tutorial code for wxPython,
it is working properly when i tell it to import * from wxPython.wx
but with an error about the package,
i've done as i was told to change the import to wx
and change all wxsomething to wx.something
but when i start it it gives me an error that say
Traceback (most recent call last):
File...
| |
by: Geared |
last post by:
Hello I'm new to python (been using it all of 2 weeks) and I'm trying to write a program that compares the result of an equation using two different starting numbers that the user chooses. It also lets the user choose how many time it preforms the function and the amplitude of the function . here is the code. I'm using Vista 64 bit and Python...
|
by: jorgejch |
last post by:
Hello, I've started with python (3) recently. Initialy only for scripting. Now I'm trying the object oriented bit.
I'm getting the following error message
<Atom.Atom object at 0x7f0b09597fd0>
Traceback (most recent call last):
File "./Main.py", line 7, in <module>
print (t.getAtomName())
File...
|
by: Terry Fernandez |
last post by:
Can you help me with the NameError?
def addExample(self, klass, words):
"""
* TODO
* Train your model on an example document with label klass ('pos' or 'neg') and
* words, a list of strings.
* You should store whatever data structures you use for your classifier
* in the NaiveBayes class.
* Returns...
|
by: dashtons7 |
last post by:
I get the following message when I try to run the below program: builtins.NameError: global name 'gallons' is not defined
def main():
square_feet = float(input("Enter the square feet of the wall that is to be painted: "))
gallons = (square_feet/115)
paint = float(input("Enter the cost of paint per gallons: "))
labor =...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |