Problems getting python-docx working with a Python script being executed by a Rails app hosted on Heroku <p>TLDR: My python script which my rails app on heroku fires fails at "from docx import Document" due to some unicode/lxml dependency thing.</p> <pre><code> 2015-08-25T22:09:35.561165+00:00 app[web.1]: Traceback (most recent call last): 2015-08-25T22:09:35.561172+00:00 app[web.1]: File "individual_insights_survey_report.py", line 4, in &lt;module&gt; 2015-08-25T22:09:35.561181+00:00 app[web.1]: from docx import Document 2015-08-25T22:09:35.561222+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/__init__.py", line 3, in &lt;module&gt; 2015-08-25T22:09:35.561254+00:00 app[web.1]: from docx.api import Document # noqa 2015-08-25T22:09:35.561277+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/api.py", line 14, in &lt;module&gt; 2015-08-25T22:09:35.561312+00:00 app[web.1]: from docx.package import Package 2015-08-25T22:09:35.561336+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/package.py", line 11, in &lt;module&gt; 2015-08-25T22:09:35.561369+00:00 app[web.1]: from docx.opc.package import OpcPackage 2015-08-25T22:09:35.561391+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/package.py", line 12, in &lt;module&gt; 2015-08-25T22:09:35.561421+00:00 app[web.1]: from .part import PartFactory 2015-08-25T22:09:35.561443+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/part.py", line 12, in &lt;module&gt; 2015-08-25T22:09:35.561473+00:00 app[web.1]: from .oxml import serialize_part_xml 2015-08-25T22:09:35.561495+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/oxml.py", line 12, in &lt;module&gt; 2015-08-25T22:09:35.561533+00:00 app[web.1]: from lxml import etree 2015-08-25T22:09:35.561628+00:00 app[web.1]: ImportError: /app/.heroku/python/lib/python2.7/site-packages/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1 </code></pre> <p>I thought this might be a versioning thing, but can't seem to find versions that will work as it does locally. This is probably a Python + Heroku thing as this is my first time trying to any sort of Python on Heroku.</p> <p>Specifically I found this <a href="https://mailman-mail5.webfaction.com/pipermail/lxml/2012-September/006572.html" rel="nofollow">mailgroup post</a> which mentions:</p> <blockquote> <p>lxml can support either UCS4 or UCS2 as the internal Unicode representation, but the switch is made at compile-time.</p> <p>Make sure that the Python that compiled etree.so and the Python that uses it are the same. Same version (at least minor as in 2.7.x, maybe micro as in 2.7.3), same architecture, and in this case same Unicode settings (UCS4 vs UCS2.)</p> <p>The easiest way to do this is to re-install lxml from the source tarball. Do you still have this issue?"</p> </blockquote> <p>So I tried to figure out what version of Python was used (failed) and then tried specifying different versions at runtime.txt to try and make it work.</p> <blockquote> <p><strong>Caveat:</strong> here's a lot of pieces in the chain and I'm not very familiar with most of them -- so if I need to provide more information to give context -- please let me know!</p> </blockquote> <p><strong>Full Context:</strong> My company has a Ruby on Rails Webapp that's basically a self service platform for generating data reports for our Client Delivery team.</p> <p>The Rails App, via a click of a button, should fire a Python script which opens up an Excel Spreadsheet (openpyxl) and does runs some data analysis on it and then outputs a report in a Microsoft Word (python-docx) document that is downloaded in a zip file.</p> <p>This is definitely a suboptimal/overly complicated way to do this, but I inherited the Webapp and am just trying to work within its structure for now.</p> <p>I have the Python script working fine when run locally and stand alone (no rails/ruby/heroku) with:</p> <pre><code>Python ver: 2.7.5 openpyxl==2.2.5 python-docx==0.8.5 </code></pre> <p>I've tried the heroku app with: Python versions: 2.7.3, 2.7.5, 2.7.9, 2.7.10 with the error above. This is with requirements.txt looking like:</p> <pre><code>python-docx==0.8.5 openpyxl==2.2.5 lxml==3.4.4 </code></pre> <p>Added lxml to be safe.</p> <p>When I use Python versions: 3.2.5, 3.3.3</p> <p>Where I get this error: </p> <pre><code> 2015-08-25T23:38:59.793177+00:00 app[web.1]: ImportError: No module named site </code></pre> <p>Any help on how to resolve this would be great! Do I need to re-install Python or a module? Is that even doable on Heroku? Am I missing a dependency? A configuration thing? Help :) </p>