3

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']

o01
  • 5,191
  • 10
  • 44
  • 85

1 Answers1

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

DevLounge
  • 8,313
  • 3
  • 31
  • 44
  • Yes, both template.py and template.pyc are listed there. – o01 Aug 05 '13 at 19:56
  • Oh, then there another unexpected behaviour. What is your PYTHONPATH? – DevLounge Aug 05 '13 at 19:57
  • I'm using virtualenv, yes. Hang on, I'll update the question with the output. – o01 Aug 05 '13 at 19:58
  • file -I foobar.py gives charset=us-ascii – o01 Aug 05 '13 at 20:34
  • 2
    Crap, I think I found the problem. The python binary running the foobar.py file wasn't the same as the one I had in my virtual environment. As such the virtualenv python binary had access to all the modules installed to it, but it was never being used. I apologize for being retarded and wasting your time. Thank you very much for trying to help me though. It's fixed now. – o01 Aug 05 '13 at 20:52
  • 1
    It's fine, glad you found. Because I was running out of ideas ;-) – DevLounge Aug 05 '13 at 20:54