Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm/Django Setup: cannot import charset from email?

I've been asked to contribute to some in-production Python/Django code. I'm setting it up in PyCharm. When I run the app, I get this error message:

File "/myApp/myVirtualEnvironment/lib/python2.7/site-packages/django/core/mail/message.py",
 line 8, in <module>
  from email import (charset as Charset, encoders as Encoders)
   ImportError: cannot import name charset

What could be causing this?

like image 646
VikR Avatar asked Jan 25 '26 05:01

VikR


1 Answers

That may be caused by the name shadowing trap.

A cause may be that you are shadowing the Charset class, which is defined in the email.charset module, when you import from email import (charset as Charset, encoders as Encoders).

Another probable cause, supported by this issue:
If you check your file tree, you may find a file named charset.py or Charset.py which shadows the above mentioned

Search your files and you will find what casts the shadow.

like image 109
John Moutafis Avatar answered Jan 27 '26 18:01

John Moutafis