473,549 Members | 2,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[NameError] global name 'ImageDraw' is not defined

3 New Member
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

Expand|Select|Wrap|Line Numbers
  1. from PIL import *
I solve this code line with try-except

Expand|Select|Wrap|Line Numbers
  1. try:
  2.     from PIL import *
  3. except AttributeError: #module has no attribute ImageN
  4.     import Image
  5.     import ImageDraw
  6.     import ImageFont
  7.  
My orginal code part

Expand|Select|Wrap|Line Numbers
  1. class capsGen(object):
  2.     def __init__(self):
  3.         pass
  4.  
  5.     def videoGen(self,path):
  6.         iv = InputVideoStream()
  7.         iv.open(path)
  8.         self.videoHead(path)
  9.         print self.topDuration
  10.         frameDiff = list(enumerate(iv.readframe())) #bmp -> [io][1]
  11.         self.totalFrame = frameDiff [-1][0]
  12.         #16 imgs
  13.         self.genImgs = []
  14.         curImg = 0
  15.         while True:
  16.             if curImg < 16:
  17.                 self.genImgs.append(randint(1,self.totalFrame))
  18.                 curImg = curImg + 1 
  19.             else:
  20.                 break
  21.  
  22.  
  23.         try:
  24.             src = PIL.Image.open("src.png")
  25.             ciz = PIL.ImageDraw.draw(src)
  26.             ft = PIL.ImageFont.truetype("arial.ttf",32)
  27.             ciz.text((190,15),self.fileName,font=ft) #fileName
  28.             src.save("1.png")
  29.  
  30.  
  31.             #print frameDiff[5][0]
  32.             for i in self.genImgs:
  33.                 imj = PIL.Image.open(StringIO.StringIO(frameDiff[i][1])) #base io -> [capsNo][1]
  34.                 imj.save("%s.png"%i)
  35.         except NameError:
  36.             src = Image.open("src.png")
  37.             ciz = ImageDraw.draw(src)
  38.             ft = ImageFont.truetype("arial.ttf",32)
  39.             ciz.text((190,15),self.fileName,font=ft) #fileName
  40.             src.save("1.png")
  41.  
  42.  
  43.             #print frameDiff[5][0]
  44.             for i in self.genImgs:
  45.                 imj = Image.open(StringIO.StringIO(frameDiff[i][1])) #base -> [io][1]
  46.                 imj.save("%s.png"%i)
  47.  
  48.  
  49.  
My error,

Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "o.py", line 275, in (module)
  3.     run = capsGen()
  4.   File "o.py", line 42, in __init__
  5.     self.videoGen() #for developers
  6.   File "o.py", line 157, in videoGen
  7.     ciz = ImageDraw.draw(src)
  8. NameError: global name 'ImageDraw' is not defined
  9.  
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.
Apr 22 '14 #1
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.
Expand|Select|Wrap|Line Numbers
  1. import Image, ImageDraw
  2.  
  3. image_name="chairs.png"
  4. im = Image.open(image_name)
  5. draw = ImageDraw.Draw(im)
  6. draw.line((0, 0) + im.size, fill=255)
  7. draw.line((0, im.size[1], im.size[0], 0), fill=128)
  8.  
  9. im.show()
Attached Images
File Type: png chairs.png (62.2 KB, 354 views)
Apr 22 '14 #2
fatihmert95
3 New Member
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 *

Expand|Select|Wrap|Line Numbers
  1. import Tkinter as tk
  2.  
And, my project file in some .open functions, I changed to these names.

Thank for interest.
Good works.
Apr 23 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
6692
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...
8
10529
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()
2
23739
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...
1
11693
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'>:...
3
18012
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...
2
44063
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...
4
4243
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...
1
2993
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...
3
2419
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 =...
0
7715
Oralloy
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. ...
0
7956
jinu1996
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...
1
7469
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...
0
7808
tracyyun
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...
0
6040
agi2029
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...
0
5087
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...
0
3498
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...
1
1935
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
0
757
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.