Search code examples
pythonwindowsbatch-filepython-docx

Attempting to install python-docx (error: Unable to find vcvarsall.bat)


I have tried everything and I have no idea where to go from here. When I call the command pip install python-docx I get this:

    running build_ext
building 'lxml.etree' extension
error: Unable to find vcvarsall.bat

----------------------------------------
Command "c:\users\alex\appdata\local\programs\python\python35-32\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Alex\\AppData\\Local\\Temp\\pip-build-u2i_l872\\lxml\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Alex\AppData\Local\Temp\pip-26nq6ot7-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Alex\AppData\Local\Temp\pip-build-u2i_l872\lxml

at the end.

I have tried locating vsvarsall.bat and setting the path. I can't seem to find it in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools and there is no tool folder in C:\Program Files\Microsoft Visual Studio 12.0\Common7. I'm on 64bit Windows 10 and python 3.5.1.


Solution

  • This is a pretty common issue people run into with Python modules. You can read up more on it here

    What you can do is install a precompiled version of lxml, which is a module that python-docx relies upon. You can identify this requirement by looking at the error message, or by looking at the python-docx github page here, which lists all requirements for python-docx.

    Luckily, Christoph Golke provides some precompiled modules for us, available here. <--- Hotlink that, you'll use it quite often.

    Download and install the lxml module first from Christoph Golke, then try rerunning your pip install.