Python ImportError email module: no module named utils

My installation of the Python requests library has been working fine for several months, and today she decided to break.

Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 58, in <module> from . import utils File "/usr/local/lib/python2.7/dist-packages/requests/utils.py", line 26, in <module> from .compat import parse_http_list as _parse_list_header File "/usr/local/lib/python2.7/dist-packages/requests/compat.py", line 7, in <module> from .packages import chardet File "/usr/local/lib/python2.7/dist-packages/requests/packages/__init__.py", line 3, in <module> from . import urllib3 File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/__init__.py", line 10, in <module> from .connectionpool import ( File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connectionpool.py", line 37, in <module> from .request import RequestMethods File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/request.py", line 6, in <module> from .filepost import encode_multipart_formdata File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/filepost.py", line 8, in <module> from .fields import RequestField File "/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/fields.py", line 1, in <module> import email.utils ImportError: No module named utils 

The problem with calling utils is related to the email module in Python 2.7

 >>> import email >>> import email.utils Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named utils 

utils clearly part of the Python email library, but cannot be accessed. If I uninstall and reinstall:

 $ sudo pip install email Collecting email Downloading email-4.0.2.tar.gz (1.2MB) 100% |████████████████████████████████| 1.2MB 286kB/s Installing collected packages: email Running setup.py install for email Successfully installed email-4.0.2 

Actually the worst of all utils.py . What am I doing wrong?

 $ ls /usr/local/lib/python2.7/dist-packages/email/ base64mime.py errors.py header.py message.py parser.pyc base64mime.pyc errors.pyc header.pyc message.pyc quoprimime.py charset.py feedparser.py __init__.py mime quoprimime.pyc charset.pyc feedparser.pyc __init__.pyc _parseaddr.py test encoders.py generator.py iterators.py _parseaddr.pyc utils.py encoders.pyc generator.pyc iterators.pyc parser.py utils.pyc 
+7
python-requests
source share
1 answer

Most likely, one of your own modules in the module search path (including the current working directory) is actually called email . This will force Python to pick up this module instead, and it will close the email module from the standard library, which will result in an import error.

Rename this module to another and you should be good.

+10
source share

All Articles