0

When I try to launch an app made with pyramid, I get the error

    from pyramid.compat import configparser
File "/srv/lightbase/lib/python3.3/site-packages/pyramid-1.5b1-py3.3.egg/pyramid/compat.py", line 205, in <module>
    from html import escape
ImportError: cannot import name escape

When trying to pip install html, I get the error:

ImportError: No module named 'html.entities'; html is not a package

Im using a virtualenv with python3.3.4 that was compiled from code using '--enable-shared' for mod_wsgi use.

Rickin
  • 9
  • 1
  • 4
  • there is [`html.escape()` function in Python 3.3](http://hg.python.org/cpython/file/3.3/Lib/html/__init__.py#l12) – jfs Feb 21 '14 at 19:29
  • So this is a pyramid bug? – Rickin Feb 21 '14 at 20:51
  • it is unlikely. Can you run `from html import escape` in the same environment but without `pyramid`? Do you have a top-level `html` module in your `sys.path` that is not from stdlib? `print(html.__file__)`. – jfs Feb 21 '14 at 21:03
  • 1
    I just checked it, had no problem with such import in Pyramid. – solusipse Feb 22 '14 at 07:50
  • 1
    You have a file named `html.py` *or* a directory named `html` in a path used when your project runs, masking the stdlib package. Rename it or delete it. – Martijn Pieters Feb 22 '14 at 08:29
  • @J.F.Sebastian Runing `import html` or `from html import escape` works, and the `print(html.__file__)` returns `/usr/local/lib/python3.3/html/__inin__.py` – Rickin Feb 24 '14 at 15:03
  • @MartijnPieters I just checked, and there is no such file or folder on my project – Rickin Feb 24 '14 at 15:04
  • @Rickin: it is not the same `python` (`/srv/lightbase/` vs. `/usr/local`). Write a [dummy wsgi application](http://stackoverflow.com/q/12173971/4279) to run it in the *same* environment as your wsgi app with pyramid and try `from html import escape` there. – jfs Feb 24 '14 at 15:50
  • @J.F.Sebastian At first, It didn't work also but I've did something else to fix it, will post as answer. – Rickin Feb 24 '14 at 17:26
  • @Rickin: yet you get the error. What happens when you add `import html`, and `print(html.__file__)` somewhere in your project, before importing `pyramid`? – Martijn Pieters Feb 24 '14 at 17:26
  • @MartijnPieters It returns the same thing, apparently, html's files stay not on `lib/python3.x/site-packages` but on `/lib/python3.x`, so wsgi doesn't read it – Rickin Feb 24 '14 at 17:51
  • @Rickin: `lib/python3.x` is *definitely* being read by WSGI programs, unless you completely cleared the `sys.path` module search path. – Martijn Pieters Feb 24 '14 at 18:04

1 Answers1

0

The version of python I used was compiled from most recent code release, and I was using mod_wsgi pre-compiled from debian 6 default repository, removing it and compiling my own mod_wsgi with most recent version was enough to fix the problem. I think that means they where not compatible.

Since pip install html/easy_install html didn't work, symlinking /usr/local/python3.3/html to the virtualenv site-packages folder made the interpreter read it as a package. This may not be the greatest solution, but I'll make it the correct answer until a better option comes.

Rickin
  • 9
  • 1
  • 4
  • `html` is part of the standard library. If linking it into the `site-packages` folder helps, then all you did is make it appear somewhere else in your `sys.path` search order, before the other version that is breaking your code is being found. – Martijn Pieters Feb 24 '14 at 18:06
  • @MartijnPieters You're right, the problem was that my mod_wsgi version wasn't looking for the standard librarys, I guess something changed in the way they are stored on olders python3 releases – Rickin Feb 25 '14 at 13:05