Wednesday 27 September 2017

Django Python Web App Development - Python XHTML2PDF Library error FIXED - "ImportError: cannot import name inputstream django" Solved

cannot import name inputstream, Django, Django alirazabhayani, Django Full Stack Development ali raza bhayani, html5lib, inputstream, Python, Python alirazabhayani, xhtml2pdf

While working on a Django Web Application using Python, I recently encountered an error while using a library named xhtml2pdf. This library is a Python library for exporting xhtml to PDF.

While using it in Django Web framework for developing a hassle free web service to export customized HTML templates into PDF, I encountered some error which I had to dig into the library to find the actual problem and its solution. I noticed that this problem of "cannot import name inputstream django" was faced by many people and therefore writing this post to document it. Please note that this proposed solution is workable for Python 2.7 and hasn't been checked on Python v.3.x .

When I installed xhtml2pdf library and used it in Django Web framework, I encountered following error:
 importerror: cannot import name inputstream 
Following trace shows that the error is actually triggered from html5lib which is one of the dependencies of xhtml2pdf:
File "/usr/home/username/virtualenvs/projectname/lib/python2.7/site-packages/xhtml2pdf/", line 17, in 
    from html5lib import treebuilders, inputstream 
ImportError: cannot import name inputstream
Due to broken dependencies of xhtml2pdf and lack of documentation, I had to dig in the module which revealed that this error was coming due to the fact that xhtml2pdf requires a specific version of html5lib to work properly. To solve this issue, I installed html5lib's version 1.0b8 in the following way:
$ pip install html5lib==1.0b8
If you had previously installed html5lib's different version, you will have to uninstall it first by running following command on your terminal or virtual environment:
$ pip uninstall html5lib


  1. Foodgram online food delivery service
    Food delivery app is certainly one of the vital apps that any food lover fans will have on their smartphones. You literally wait for your next meal. Well, you are not the only one. There are millions of food lovers who are just incorporate food into their lifestyle. Nowadays, there are tons of useful mobile apps that are literally dedicated to food. Right from piling up recipes, watching someone cook to ordering online food, there are food delivery apps for every foodie lovers. What if you are craving for foods in the midnight, Foodgram will find you through your location to solve your late-night cravings. Yes! Foodgram is the first and best solution in this food-industry to solve your late-night cravings.

  2. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. android app maker


  3. Hi!
    Thanks to shearing this post. This blog is amazing and interest.
    We just wanna inform you, TravelingBD

  4. We have established our own product development company Weabers Inc because we believe that there is always a better way to do things. We are truly passionate about experiences, user interfaces and developing the best possible digital products.

  5. Avant-garde Productions is creative business firm
    we works for aesthetics in various forms of media.

  6. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though DES-4331 PDF Dumps, ill be checking back soon to find out what additional posts you include.

  7. Thank you so much for sharing this great blog. Very inspiring and helpful too. Hope you continue to share more of your ideas.I will definitely love to read.