Forums

import error from python 2.7.6

Hi,

I'm trying to import Flask (which is one of the batteries included) after starting up python 2.7.6 but I'm getting an error ImportError: No module named Utils. This is after starting python from the bash console (Bash console 6134952)

My commands and the full error message are below:

00:37 ~ $ uname -a
Linux harry-liveconsole4 4.4.0-83-generic #106-Ubuntu SMP Mon Jun 26 17:54:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

00:37 ~ $ python

Python 2.7.6 (default, Oct 26 2016, 20:30:19)

[GCC 4.8.4] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> from flask import Flask

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/flask/__init__.py", line 17, in <module>
    from werkzeug.exceptions import abort
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/__init__.py", line 152, in <module>
    __import__('werkzeug.exceptions')
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/exceptions.py", line 71, in <module>
    from werkzeug.wrappers import Response
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 26, in <module>
    from werkzeug.http import HTTP_STATUS_CODES, \
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/http.py", line 24, in <module>
    from email.Utils import parsedate_tz
ImportError: No module named Utils

Thanks for your help

[edit by admin: formatting]

Do you have a file in your home directory called email.py, or a directory there called email that contains a file called __init__.py? If so, that would explain the problem.

When you run a Python interpreter, it sets up a system path that has the current working directory first. So when some code -- regardless of whether it's your own code, or something deep inside Flask, tries to import email.Utils, then it will look at your own email module first, and will fail if it can't find the Utils class/module in there.

thank you very much!

You're welcome!