2

I have Python 2.7 and I was trying to use PyQuery, so for a test I just typed "import PyQuery" and I got an error:

Traceback (most recent call last):
  File "C:\Users\Jacob\Documents\dupes.py", line 1, in <module>
    import pyquery
  File "C:\Python27\lib\site-packages\pyquery-1.2.1-py2.7.egg\pyquery\__init__.py", line 12, in <module>
    from .pyquery import PyQuery
  File "C:\Python27\lib\site-packages\pyquery-1.2.1-py2.7.egg\pyquery\pyquery.py", line 8, in <module>
    from lxml import etree
ImportError: No module named lxml

So I went to the command prompt and tried to install lxml, but I got this:

Building lxml version 2.3.5.
Building without Cython.
ERROR: 'xslt-config' is not recognized as an internal or external command,
operable program or batch file.

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
error: Setup script exited with error: Unable to find vcvarsall.bat

I don't really understand what's wrong or what I should do...can someone help?

Thanks.

EDIT:

In response to the comment, I used easy install...

Christian Hudon
  • 1,881
  • 1
  • 21
  • 42
Marcus Johnson
  • 2,505
  • 6
  • 22
  • 27

2 Answers2

3

From installation instructions of lxml:

easy_install --allow-hosts=lxml.de,*.python.org lxml

On MS Windows, the above will install the binary builds that we provide. If there is no binary build of the latest release yet, please search PyPI for the last release that has them and pass that version to easy_install like this:

easy_install --allow-hosts=lxml.de,*.python.org lxml==2.2.2

[edit]

Ok, 2.2.2 was en example. I went and looked for you, try:

easy_install --allow-hosts=lxml.de,*.python.org lxml==2.3
favoretti
  • 29,299
  • 4
  • 48
  • 61
  • You should also add the part about the manual dependency information unless the OP has trouble. He can just install those manually. – jdi Aug 09 '12 at 19:58
  • 1
    @jdi: For MS Windows, the binary egg distribution of lxml is statically built against the libraries, i.e. it already includes them. There is no need to install the external libraries if you use an official lxml build from PyPI. Unless you know what you are doing, this means: do not install libxml2 or libxslt if you use a binary build of lxml. Just use easy_install by following the installation instructions above. Only if you want to upgrade the libraries and/or compile lxml from sources, you should install a binary distribution of libxml2 and libxslt. – favoretti Aug 09 '12 at 20:07
  • His install process is obviously not picking up a binary egg. It must be trying to build it. – jdi Aug 09 '12 at 20:08
  • Yes, cause he just typed in my example without following the instruction to look :) I went to search for him, 2.3 has binary. – favoretti Aug 09 '12 at 20:09
  • @MarcusJohnson: see my latest edit with the version that _does_ include binary :) – favoretti Aug 09 '12 at 20:14
0

Unless your Windows environment is properly set (proper Visual Studio version for your Python version and all that), you should download binary eggs and install them. I know setuptools (and possibly distribute) support installing binary executable packages on Windows (the distutils-based executables only - the ones with the blue background and old dot-matrix Python logo; sorry, but I haven't done Python on Windows in a couple months). Pip doesn't (probably what you are/were using).

But to answer your question, the batch file vcvarsall.bat is used to set the environment variables necessary for building Visual Studio projects/solutions (and generally using any Visual Studio tools) from the command line. It's not in your PATH by default, and since pip is trying to use it to build lxml properly, it fails.

My advice: unless you know how to use Visual Studio command line tools, you're much better off using binary packages on Windows.

darkphoenix
  • 2,147
  • 3
  • 13
  • 14