How to install lxml on Windows

前端 未结 7 1863
后悔当初
后悔当初 2020-12-09 08:53

I\'m trying to install lmxl on my Windows 8.1 laptop with Python 3.4 and failing miserably.

First off, I tried the simple and obvious solution: pi

相关标签:
7条回答
  • 2020-12-09 09:02

    I had this issue with a requirements file that listed lxml==4.2.1. However, I was able to fix the problem by updating this to lxml==4.2.5.

    0 讨论(0)
  • 2020-12-09 09:07

    First, following the comments, I downloaded the lxml-3.4.2-cp34-none-win_amd64.whl file and tried to open it with a pip install, but it just told me it wasn't a valid wheel file on my system or something.

    Then, I downloaded the win_32 file and it worked! Maybe it's because I have an Intel processor and AMD64 is, unsurprisingly, only for AMD processors.

    0 讨论(0)
  • 2020-12-09 09:08

    I also meet this problem recently. pip can't not work on .whl file. Instead of fixing this, i install it through .exe file. you can download it from here.Please choose the right version of your python. Hope this can help you.

    0 讨论(0)
  • 2020-12-09 09:08

    From the distributer's website, the correct command is:

    pip install lxml==3.4.4
    

    Of course, update version number to match the latest version.

    Reference: https://pypi.org/project/lxml/3.4.4/

    0 讨论(0)
  • 2020-12-09 09:11

    These instructions are for Windows7 or Windows8 with Python3.4.

    However, they should work for various versions as the releases of python and other respective prerequisites change/evolve:

    1. Install Python3.4:
      1. Download the last release of Python3.4 from the downloads page HERE
        • Direct link for Win32 MSI installer -> HERE
      2. Simply run the MSI to install python. It will register itself in the registry, and appear in Add/REmove Programs.
      3. NOTE: my instructions that follow assume that you choose to install python to the default path of C:\python34\ when asked during the Python Installation Wizard
    2. Add the C:\python33\ and C:\python34\scripts folders to the system path by adding those directories to the PATH environment variable from the Control Panel > System > Advanced System Settings link (Advanced Tab) > Environmental Variables (Button).
    3. Install OpenSSL:
      1. Download Win32 OpenSSL page from HERE for your version of Windows and PC architecture
      2. Download Visual C++ 2008 redistributables for your version of Windows and PC architecture
      3. Download OpenSSL for your version of Windows and architecture (the regular version, not the light one)
      4. Add the c:\openssl-win32\bin (or similar) directory to your PATH, the same way you added C:\python34 and C:\python34\scripts above.
    4. Install Setuptools (get-pip.py should install Setuptools for you), but, just in case...
      1. Download ez_setup.py HERE and save it in C:\python34\scripts
      2. Run C:\python34\scripts> python ez_setup.py
    5. Install PIP
      1. Download get-pip.py from HERE and save it in C:\python34\scripts
      2. Run C:\python34\scripts> python get-pip.py
    6. Install LXML
      1. Download LXML 3.4.4 from HERE for your version of Windows and PC architecture
      2. Run the EXE file
    0 讨论(0)
  • 2020-12-09 09:20

    Looks like today in 2018, lxml can be installed from PyPI:

    C:\Users\Administrator>"c:\Program Files\Python37\python.exe" -m pip install -U pip wheel setuptools
    Collecting pip
      Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
        100% |████████████████████████████████| 1.3MB 3.3MB/s
    Collecting wheel
      Downloading https://files.pythonhosted.org/packages/5a/9b/6aebe9e2636d35d1a93772fa644c828303e1d5d124e8a88f156f42ac4b87/wheel-0.32.2-py2.py3-none-any.whl
    Collecting setuptools
      Downloading https://files.pythonhosted.org/packages/96/06/c8ee69628191285ffffddffb277bd5abdf769166e7a14b867c2a172f0175b1/setuptools-40.4.3-py2.py3-none-any.whl (569kB)
        100% |████████████████████████████████| 573kB 2.9MB/s
    Installing collected packages: pip, wheel, setuptools
      Found existing installation: pip 10.0.1
        Uninstalling pip-10.0.1:
          Successfully uninstalled pip-10.0.1
      The script wheel.exe is installed in 'c:\Program Files\Python37\Scripts' which is not on PATH.
      Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
      Found existing installation: setuptools 39.0.1
        Uninstalling setuptools-39.0.1:
          Successfully uninstalled setuptools-39.0.1
    Successfully installed pip-18.1 setuptools-40.4.3 wheel-0.32.2
    
    C:\Users\Administrator>pip install lxml
    Collecting lxml
      Downloading https://files.pythonhosted.org/packages/d7/9d/1aa28aa9d293a816baec6c37328d6465b722b2ff3f4d1e93ed56e87813ee/lxml-4.2.5-cp37-cp37m-win_amd64.whl (3.6MB)
        100% |████████████████████████████████| 3.6MB 1.6MB/s
    Installing collected packages: lxml
    Successfully installed lxml-4.2.5
    
    C:\Users\Administrator>python
    Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from io import BytesIO
    >>> some_file_or_file_like_object = BytesIO(b"<root>data</root>")
    >>> from lxml import etree
    >>> tree = etree.parse(some_file_or_file_like_object)
    >>> etree.tostring(tree)
    b'<root>data</root>'
    
    0 讨论(0)
提交回复
热议问题