ImportError: no module named mako.template

2019-07-17 20:45发布

问题:

This line of code in my foobar.py file:

from mako.template import *

results in an

ImportError: No module named mako.template

How can I fix this? Both help('modules') and repr(mako) in my Python console assures me that the mako module is installed and available.

I'm on a Mac by the way, running Python 2.6 for this particular project.

As requested, this is the output from running pip freeze

  • Mako==0.8.1
  • MarkupSafe==0.18
  • PyYAML==3.10
  • wsgiref==0.1.2

As requested, this is my sys.path

['', '/Users/username/env/myProject/lib/python26.zip', '/Users/username/env/myProject/lib/python2.6', '/Users/username/env/myProject/lib/python2.6/plat-darwin', '/Users/username/env/myProject/lib/python2.6/plat-mac', '/Users/username/env/myProject/lib/python2.6/plat-mac/lib-scriptpackages', '/Users/username/env/myProject/Extras/lib/python', '/Users/username/env/myProject/lib/python2.6/lib-tk', '/Users/username/env/myProject/lib/python2.6/lib-old', '/Users/username/env/myProject/lib/python2.6/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Users/username/env/myProject/lib/python2.6/site-packages']

回答1:

Do you have template.py inside your .env/lib/python2.6/site-packages/mako directory?

Are you using virtualenv, or have installed mako in /Library/Python/2.6/site-packages?

Please paste an output of pip freeze


Update:

Have you checked if there is no CR/LF or wrong character on this import line?

What is the encoding of your foobar.py file?

file -I foobar.py

it should contain utf-8 or ascii