ImportError: No module named 'exceptions' - Python3

12,880 views
Skip to first unread message

abhijeet shete

unread,
Aug 12, 2013, 1:21:32 AM8/12/13
to django-users
Hi Folks,

    I ported my project from python2.7 to python3 using 2to3 module. One of my class is inherited from Exception class, but after porting to python3 i am getting No module named 'exceptions'  error.

    My class looks something like this :-

from exceptions import Exception
class A(Exception):
    def __init__(self, value=None):
        self.value = value

And the error which I am getting is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'exceptions'


I tried to import exceptions in python3 shell but there also I am getting same error.
Is there any problem with my code or did I missed something while porting or python3 itself has some problem while importing exceptions ?


Thanks and Regards.
Abhijeet Shete

Jani Tiainen

unread,
Aug 12, 2013, 2:25:11 AM8/12/13
to django...@googlegroups.com
Hi,

In Python 3 exceptions module was removed and all standard exceptions were moved to builtin module. Thus meaning that there is no more need to do explicit import of any standard exceptions.


On Mon, 12 Aug 2013 10:51:32 +0530
abhijeet shete <abhijeet...@gmail.com> wrote:

> Hi Folks,
>
> I ported my project from python2.7 to python3 using 2to3 module. One of
> my class is inherited from Exception class, but after porting to python3 i
> am getting *No module named 'exceptions' *error.
>
> My class looks something like this :-
>
> *from exceptions import Exception*
> *class A(Exception):*
> * def __init__(self, value=None):*
> * self.value = value*
> *
> *
> And the error which I am getting is
> *
> *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named 'exceptions'
>
>
> I tried to import exceptions in python3 shell but there also I am getting
> same error.
> Is there any problem with my code or did I missed something while porting
> or python3 itself has some problem while importing exceptions ?
>
>
> Thanks and Regards.
> Abhijeet Shete
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Mike Dewhirst

unread,
Aug 12, 2013, 2:30:40 AM8/12/13
to django...@googlegroups.com
On 12/08/2013 3:21pm, abhijeet shete wrote:
> Hi Folks,
>
> I ported my project from python2.7 to python3 using 2to3 module.
> One of my class is inherited from Exception class, but after porting to
> python3 i am getting *No module named 'exceptions' *error.
>
> My class looks something like this :-
>

Try it without importing Exception. Looking at django.core.exceptions it
seems specifically importing Exception is not required.

> *from exceptions import Exception*
> *class A(Exception):*
> * def __init__(self, value=None):*
> * self.value = value*
> *
> *
> And the error which I am getting is
> *
> *
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named 'exceptions'
>
>
> I tried to import exceptions in python3 shell but there also I am
> getting same error.
> Is there any problem with my code or did I missed something while
> porting or python3 itself has some problem while importing exceptions ?
>
>
> Thanks and Regards.
> Abhijeet Shete
>
Reply all
Reply to author
Forward
0 new messages