473,473 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Suggestion for improved ImportError message

Howdy,

I was just bit by

from image import annotate

ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which made it clear that the wrong image module had been found.

It would be nice if ImportError announced this up front.

cannot import name annotate from /usr/<snip>/image.pyc

Thanks,
Kent

Aug 13 '08 #1
9 1122
Dnia Wed, 13 Aug 2008 20:55:38 +0000 (UTC), Kent Tenney napisa³(a):
from image import annotate

ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which made it clear that the wrong image module had been found.

It would be nice if ImportError announced this up front.
Then go for it :-) You can prepare a patch and ask on python-dev
if the developers are interested.

I was never hacking the import things on C level before,
but a hint: you have to modify import_from function from
Python/ceval.c

My quick attempt:
http://www.stud.umk.pl/~wojtekwa/pat...-py2.5.1.patch
--
Regards,
Wojtek Walczak,
http://www.stud.umk.pl/~wojtekwa/
Aug 13 '08 #2
Dnia Wed, 13 Aug 2008 22:15:48 +0000 (UTC), Wojtek Walczak napisa³(a):
Then go for it :-) You can prepare a patch and ask on python-dev
if the developers are interested.

I was never hacking the import things on C level before,
but a hint: you have to modify import_from function from
Python/ceval.c

My quick attempt:
http://www.stud.umk.pl/~wojtekwa/pat...-py2.5.1.patch
Uh, and an example:

Python 2.5.1 (r251:54863, Aug 14 2008, 00:04:00)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>from os import qweasd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name qweasd (/home/gminick/Python-2.5.1/Lib/os.pyc)
>>>
--
Regards,
Wojtek Walczak,
http://www.stud.umk.pl/~wojtekwa/
Aug 13 '08 #3
Then go for it You can prepare a patch and ask on python-dev
if the developers are interested.
hehe, I'll get a C level patch accepted right after I
out-swim Mike Phelps.

I was never hacking the import things on C level before,
but a hint: you have to modify import_from function from
Python/ceval.c
Am I correct in thinking that PyPy would mean low level
stuff like this will be Python instead of C?
That would be nice.

My quick attempt:
Quick indeed!
Very cool.

Thanks,
Kent

Aug 14 '08 #4
On Thu, 14 Aug 2008 01:35:44 +0000 (UTC), Kent Tenney wrote:
Then go for it You can prepare a patch and ask on python-dev
if the developers are interested.

hehe, I'll get a C level patch accepted right after I
out-swim Mike Phelps.
It's really not that hard. The only hard thing (harder than
writing the code) might be to win the acceptance of the core
developers that this change is really needed ;-)

I was never hacking the import things on C level before,
but a hint: you have to modify import_from function from
Python/ceval.c

Am I correct in thinking that PyPy would mean low level
stuff like this will be Python instead of C?
That would be nice.
I don't know PyPy, but I guess you're right here.
--
Regards,
Wojtek Walczak,
http://www.stud.umk.pl/~wojtekwa/
Aug 14 '08 #5
Lie
On Aug 14, 5:10*pm, Wojtek Walczak
<gmin...@nie.ma.takiego.adresu.w.sieci.plwrote:
On Thu, 14 Aug 2008 01:35:44 +0000 (UTC), Kent Tenney wrote:
Then go for it *You can prepare a patch and ask on python-dev
if the developers are interested.
hehe, I'll get a C level patch accepted right after I
out-swim Mike Phelps.

It's really not that hard. The only hard thing (harder than
writing the code) might be to win the acceptance of the core
developers that this change is really needed ;-)
I think the acceptance for this wouldn't be that hard since there is
no real issue for regression (the only one I could think of is for
doctest module, although I'm not sure there are any reason to test for
failed import in doctest)
I was never hacking the import things on C level before,
but a hint: you have to modify import_from function from
Python/ceval.c
Am I correct in thinking that PyPy would mean low level
stuff like this will be Python instead of C?
That would be nice.

I don't know PyPy, but I guess you're right here.

--
Regards,
Wojtek Walczak,http://www.stud.umk.pl/~wojtekwa/
Aug 15 '08 #6
Lie:
>I'm not sure there are any reason to test for failed import in doctest)<
I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations...

Bye,
bearophile
Aug 15 '08 #7
On Aug 13, 3:55*pm, Kent Tenney <kten...@gmail.comwrote:
Howdy,

I was just bit by

from image import annotate

ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which made it clear that the wrong image module had been found.

It would be nice if ImportError announced this up front.
Why? It says the file where the error originated in the traceback.
>
cannot import name annotate from /usr/<snip>/image.pyc

Thanks,
Kent
Aug 16 '08 #8
Lie
On Aug 15, 7:42*pm, bearophileH...@lycos.com wrote:
Lie:
I'm not sure there are any reason to test for failed import in doctest)<

I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations...
Why? Is there a difference in result if you have used numpy and python
code? If that is, I smell a bad code. What numpy and python code
version would return in that situation should be the same (practically
it isn't always feasible though).
Bye,
bearophile
Aug 23 '08 #9
Lie wrote:
>I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations...

Why? Is there a difference in result if you have used numpy and python
code? If that is, I smell a bad code. What numpy and python code
version would return in that situation should be the same (practically
it isn't always feasible though).
maybe the point is to use doctest to *verify* that the code generates
the same result whether or not numpy is used?

</F>

Aug 23 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carsten Gehling | last post by:
Figured out myself - I just removed the line with "from url import Url" -it doesn't seem to be used anywhere ;-) - Carsten > -----Oprindelig meddelelse----- > Fra:...
2
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
0
by: Ben McBride | last post by:
I'm trying to wrap a DLL, using SWIG, for an extension module and am having an obscure ImportError. I've been unable to find anything through the SWIG documentation and an extensive google search....
4
by: Andy | last post by:
What do people think of this? 'prefixed string'.lchop('prefix') == 'ed string' 'string with suffix'.rchop('suffix') == 'string with ' 'prefix and suffix.chop('prefix', 'suffix') == ' and ' ...
3
by: Sori Schwimmer | last post by:
Hi, I think that would be useful to have an improved version of the "try" statement, as follows: try(retrys=0,timeout=0): # things to try except: # what to do if failed
18
by: Urs Eichmann | last post by:
Make (at least Class Library) Projects shareable between VS 2003 und 2005 http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=572a25b7-4b3d-4364-8bd1-72fd99a18693 Thank...
2
by: Adam Blinkinsop | last post by:
I'm writing a set of modules to monitor remote system services, and I'm having a problem running my test scripts. When I pass the scripts into python, like so: -- $ PYTHONPATH="${TARGET_DIR}"...
1
by: Prof Rodney Coates | last post by:
Although I have been using Macs for a quarter of a century and was doing scientific programming in the '60's I am VERY new to Python on the Mac. I have been writing some very simple applications and...
0
by: Fredrik Lundh | last post by:
Kent Tenney wrote: that's what "python -v" is all about, of course. </F>
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.