2

I am using Python version 3.5.2.

I am tying to edit words and paragraphs in MSWord documents.

Before I can do that I need to install the docx module.

In command line I pointed it to path:

C:\Users\d\AppData\Local\Programs\Python\Python35-32\Scripts 

and type:

pip install python-docx. 

After hitting return, I get this error message (full output below):

"unable to find vcvarsall.bat".

How can I fix this error?


c:\Users\D\AppData\Local\Programs\Python\Python35-32\Scripts>pip install
python-docx
Collecting python-docx
  Using cached python-docx-0.8.6.tar.gz
Collecting lxml>=2.3.2 (from python-docx)
  Using cached lxml-3.6.4.tar.gz
Installing collected packages: lxml, python-docx
  Running setup.py install for lxml ... error
    Complete output from command c:\users\d\appdata\local\programs\python
\python35-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\
D\\AppData\\Local\\Temp\\pip-build-9yk1nedc\\lxml\\setup.py';f=getattr(to
kenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();ex
ec(compile(code, __file__, 'exec'))" install --record C:\Users\D\AppData\
Local\Temp\pip-pepj9c3f-record\install-record.txt --single-version-externally-ma
naged --compile:
    Building lxml version 3.6.4.
    Building without Cython.
    ERROR: b"'xslt-config' is not recognized as an internal or external command,
\r\noperable program or batch file.\r\n"
    ** make sure the development packages of libxml2 and libxslt are installed *
*
    Using build configuration of libxslt
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.5
    creating build\lib.win32-3.5\lxml
    copying src\lxml\builder.py -> build\lib.win32-3.5\lxml
    copying src\lxml\cssselect.py -> build\lib.win32-3.5\lxml
    copying src\lxml\doctestcompare.py -> build\lib.win32-3.5\lxml
    copying src\lxml\ElementInclude.py -> build\lib.win32-3.5\lxml
    copying src\lxml\pyclasslookup.py -> build\lib.win32-3.5\lxml
    copying src\lxml\sax.py -> build\lib.win32-3.5\lxml
    copying src\lxml\usedoctest.py -> build\lib.win32-3.5\lxml
    copying src\lxml\_elementpath.py -> build\lib.win32-3.5\lxml
    copying src\lxml\__init__.py -> build\lib.win32-3.5\lxml
    creating build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\__init__.py -> build\lib.win32-3.5\lxml\includes
    creating build\lib.win32-3.5\lxml\html
    copying src\lxml\html\builder.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\clean.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\defs.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\diff.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\ElementSoup.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\formfill.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\html5parser.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\soupparser.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\usedoctest.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\_diffcommand.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\_html5builder.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\_setmixin.py -> build\lib.win32-3.5\lxml\html
    copying src\lxml\html\__init__.py -> build\lib.win32-3.5\lxml\html
    creating build\lib.win32-3.5\lxml\isoschematron
    copying src\lxml\isoschematron\__init__.py -> build\lib.win32-3.5\lxml\isosc
hematron
    copying src\lxml\lxml.etree.h -> build\lib.win32-3.5\lxml
    copying src\lxml\lxml.etree_api.h -> build\lib.win32-3.5\lxml
    copying src\lxml\includes\c14n.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\config.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\dtdvalid.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\etreepublic.pxd -> build\lib.win32-3.5\lxml\includ
es
    copying src\lxml\includes\htmlparser.pxd -> build\lib.win32-3.5\lxml\include
s
    copying src\lxml\includes\relaxng.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\schematron.pxd -> build\lib.win32-3.5\lxml\include
s
    copying src\lxml\includes\tree.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\uri.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\xinclude.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\xmlerror.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\xmlparser.pxd -> build\lib.win32-3.5\lxml\includes

    copying src\lxml\includes\xmlschema.pxd -> build\lib.win32-3.5\lxml\includes

    copying src\lxml\includes\xpath.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\xslt.pxd -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\etree_defs.h -> build\lib.win32-3.5\lxml\includes
    copying src\lxml\includes\lxml-version.h -> build\lib.win32-3.5\lxml\include
s
    creating build\lib.win32-3.5\lxml\isoschematron\resources
    creating build\lib.win32-3.5\lxml\isoschematron\resources\rng
    copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib
.win32-3.5\lxml\isoschematron\resources\rng
    creating build\lib.win32-3.5\lxml\isoschematron\resources\xsl
    copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win
32-3.5\lxml\isoschematron\resources\xsl
    copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win
32-3.5\lxml\isoschematron\resources\xsl
    creating build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron
-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstra
ct_expand.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schema
tron-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_i
nclude.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematro
n-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schema
tron_message.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-sch
ematron-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schema
tron_skeleton_for_xslt1.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\
xsl\iso-schematron-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_f
or_xslt1.xsl -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schemat
ron-xslt1
    copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt
 -> build\lib.win32-3.5\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
    running build_ext
    building 'lxml.etree' extension
    error: Unable to find vcvarsall.bat
    ----------------------------------------
Command "c:\users\d\appdata\local\programs\python\python35-32\python.exe
-u -c "import setuptools, tokenize;__file__='C:\\Users\\D\\AppData\\Local
\\Temp\\pip-build-9yk1nedc\\lxml\\setup.py';f=getattr(tokenize, 'open', open)(__
file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file_
_, 'exec'))" install --record C:\Users\D\AppData\Local\Temp\pip-pepj9c3f-
record\install-record.txt --single-version-externally-managed --compile" failed
with error code 1 in C:\Users\D\AppData\Local\Temp\pip-build-9yk1nedc\lxm
l\
jwpfox
  • 5,124
  • 11
  • 45
  • 42
Johnseito
  • 315
  • 1
  • 9
  • 24
  • This is a well-known problem with installing the `lxml` Python library on Windows. A quick search on 'python-docx windows lxml install' will give you all you need, including this other question for example: http://stackoverflow.com/questions/27589971/unable-to-install-python-docx. – scanny Nov 23 '16 at 08:22
  • Thanks for the feedback. So it seems that I have to install lxml before I run pip install python-docx but which lxml should I use and how do I extract to install it ? Thanks The lxml link is below: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml – Johnseito Nov 25 '16 at 06:09

1 Answers1

1

This is a well-known problem with installing the lxml Python library on Windows.

The TL;DR version here is you install lxml from a "binary installation package" which comes pre-compiled and takes care of all the details for you.

You can find one of those here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

The 'cp' segment stands for 'C Python' (regular Python, as opposed to PyPy for example) and the version, so if you're using Python 2.7 you want one of the packages with -cp27- in the name. There are two of these, one for 32-bit and one for 64-bit. You probably want 32-bit because that's the default Python install on Windows.

Once you download the binary installation package ("wheel"), you install it using pip, e.g.:

pip install lxml‑3.6.4‑cp27‑cp27m‑win32.whl
Community
  • 1
  • 1
scanny
  • 26,423
  • 5
  • 54
  • 80
  • I am just starting out with Python. I am using Python version **3.5.2** and Window 7 Operating System **64 bit**. So according to what I use, I downloaded `lxml-3.6.4-cp35-cp35m-win_amd64.whl` and added this file to the Scripts directory C:\Users\d\AppData\Local\Programs\Python\Python35-32\Scripts then in command prompt pointing to that folder, I type `pip install lxml-3.6.4-cp35-cp35m-win_amd64.whl` and got error message: **_lxml-3.6.4-cp35-cp35m-win_amd64.whl is not a supported wheel on this platform._** – Johnseito Nov 27 '16 at 04:40
  • @Johnseito I don't think I can help you with that, there are just too may variables. I'd start with moving the .whl file somewhere else, like your Desktop or Documents folder. It doesn't need to be in a special place and its tough to say whether the "special" folder its in now is part of the problem. Then I'd suspect that the Python that `pip` is using is not the 3.5.2 install; you can have multiple Python installs on one machine. The other thing I can think of is the pip version might be too old, try `pip --version` and upgrade if its not at least version 8.something. – scanny Nov 27 '16 at 05:43
  • Ok, Normally when I installed Python 3.5.2 it comes with pip version 8.1.1 and then I can upgrade it to 9.0.1. With both pip version and no matter where I put the file, the same error message occurs. I am going to put that error message in google and do some research on it. – Johnseito Nov 28 '16 at 02:42
  • I am happy to say that I did a bit of research and found out the problem and was able to solve it. I have to select the 32 bit lxml binary `lxml‑3.6.4‑cp35‑cp35m‑win32.whl`, even though my system is 64 bit, because python install has 32 bit by default for windows according to this: http://stackoverflow.com/users/6650102/aurora0001 – Johnseito Nov 28 '16 at 02:59
  • Ah, really good to know @Johnseito, and glad you got it working :) I'll update my answer to reflect that additional detail. Don't forget to accept what you consider the best answer. That's an important part of what makes SO work :) – scanny Nov 28 '16 at 05:26
  • How to accept what I consider is the best answer ? :) – Johnseito Nov 28 '16 at 17:24
  • @Johnseito You click on the checkmark next to that answer. – scanny Nov 28 '16 at 19:18