I get “legacy-install-failure” when I try to install lxml in a Windows Python environment.

Hello, this is Yamapan.
I saw this qiita article and thought it looked interesting, so I decided to give it a try, but I got stuck, so I'm writing this down as a reminder.

I'll try to use the popular ChatGPT in Python.
https://qiita.com/ekusiadadus/items/3304c4832106b244a60f

It's advent calendar season these days and I'm enjoying many interesting articles that make me want to try it even if it's in a different field.
Let's do it again next week.

What is ChatGPT?


It's like.

About ChatGPTWhat is ChatGPT, I asked.

ChatGPT is a large language model trained by OpenAI.
The model is based on natural language understanding and is capable of generating interactive text.
The model is trained on a large corpus of documents and has the ability to solve complex natural language problems.
ChatGPT is often used to develop interactive systems, such as interactive applications and support chatbots.
It is also used to build interactive AI systems and for text generation tasks.

For more information on how to use ChatGPT itself, please refer to the following.

ChatGPT, which answers questions in fluent Japanese, is now available - try it out here
https://softantenna.com/blog/chat-gpt-beta/

Environment Information

OS : Windows 10 21H2
Python Version : 3.11.1
PIP Version : 22.3.1

Advance preparation

This is the first time I have created a Python environment in a Windows environment.
https://www.python.jp/install/windows/install.html
I heard that there was a way to use Anaconda, but I didn't use it this time because I didn't want to add anything unnecessary.

Python Anaconda is a Python distribution. A distribution is a collection of pre-compiled and pre-configured software. Anaconda is a set of everything you need for Python development. Because Python development is largely complemented by libraries, it is necessary to install useful libraries. However, it is difficult for newcomers to Python to know which libraries to install, and Anaconda makes up for this. (translated from Japanese)
・Python Anacondaとは?
https://www.creativevillage.ne.jp/category/topcreators/web-creator/web-programmer/72837/#head-1

Stuck points

Let's use the popular ChatGPT in Python for a good cause!
https://qiita.com/ekusiadadus/items/3304c4832106b244a60f
This time I executed the following command introduced in the above article, and it was going well until halfway through, but I got an error at the lxml part.

pip install chatgptpy --upgrade
Error excerpt
      creating buildtemp.win-amd64-cpython-311Releasesrclxml
      "C:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.34.31933binHostX86x64cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrclxmlincludes -IC:UsersvainfAppDataLocalProgramsPythonPython311include -IC:UsersvainfAppDataLocalProgramsPythonPython311Include "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.34.31933include" "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCAuxiliaryVSinclude" "-IC:Program Files (x86)Windows Kits10include10.0.22000.0ucrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\um" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\shared" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\winrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\cppwinrt" "-IC:Program Files (x86)Windows KitsNETFXSDK4.8includeum" /Tcsrclxmletree.c /Fobuildtemp.win-amd64-cpython-311Releasesrclxmletree.obj -w
      cl : コマンド ライン warning D9025 : '/W3' より '/w' が優先されます。
      etree.c
      C:UsersvainfAppDataLocalTemppip-install-jd_6qz64lxml_d61b68255dd74341831e31c1d5634d1esrclxmlincludes/etree_defs.h(14): fatal error C1083: include ファイルを開けません。'libxml/xmlversion.h':No such file or directory
      Compile failed: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe' failed with exit code 2
      "C:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.34.31933binHostX86x64cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -I/usr/include/libxml2 "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.34.31933include" "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCAuxiliaryVSinclude" "-IC:Program Files (x86)Windows Kits10include10.0.22000.0ucrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\um" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\shared" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\winrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22000.0\cppwinrt" "-IC:Program Files (x86)Windows KitsNETFXSDK4.8includeum" /TcC:UsersvainfAppDataLocalTempxmlXPathInitp8a2z2_7.c /FoUsersvainfAppDataLocalTempxmlXPathInitp8a2z2_7.obj
      xmlXPathInitp8a2z2_7.c
      C:UsersvainfAppDataLocalTempxmlXPathInitp8a2z2_7.c(1): fatal error C1083: include ファイルを開けません。'libxml/xpath.h':No such file or directory
      *********************************************************************************
      Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
      *********************************************************************************
      error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lxml

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

The following commands did not help.

pip install lxml
pip install --upgrade pip
pip install --upgrade wheel
pip install --upgrade setuptools

What is lxml library?

lxml is a library for working with xml and html in Python. It is often used for scraping, i.e., creating programs that parse html from websites and extract information from it.
To analyze html in Python, you can use modules such as "htmllib" or "Beautiful Soup," but lxml is said to be faster and more flexible than those modules.
How to use Python's lxml library (for beginners) https://magazine.techacademy.jp/magazine/19063

Solution

In conclusion, I downloaded lxml-4.9.0-cp311-cp311-win_amd64.whl from the following site, and by specifying the downloaded file and installing it, I was able to proceed with the installation successfully and execute the command I initially wanted to execute I was able to execute the commands I initially wanted to execute.
・Archived: Unofficial Windows Binaries for Python Extension Packages
https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml

pip install ./lxml-4.9.0-cp311-cp311-win_amd64.whl

The following is a very informative site.
・WindowsのPython3.5でlxmlを入れようとしたら詰んだ
https://y-mattu.hatenablog.com/entry/2016/01/17/145725
・Python3.5でlxmlのインストールができない(Windows)
https://saitune.hatenablog.com/entry/2016/03/29/152328

The following are also useful sites, although not pinpointed.
・pip installでerror: legacy-install-failureが出た時の対処
https://monaledge.com/article/592
I see, I thought that maybe there is a version dependency or something and the repository doesn't have the lxml I want to install.

I was able to touch ChatGPT in Python.

I could finally talk about it.

Other sites we referred to

These are the sites that we checked during the overall construction of this environment.
・コード合ってるのにSyntaxError: invalid syntaxが出る問題【visual studio code / Python】
https://www.rakugochunen.com/programming/syntaxerror-invalid-syntax-visual-studio-code-python

・pythonでImportError: No module named ・・・が出たときの確認方法と対処
https://plus-idea.net/python-import-error-no-module-name/#i-2

・【python】pip installの際に「error: Microsoft Visual C++ 14.0 is required」が発生した場合の対応方法
https://tech.nkhn37.net/python-pip-install-error-microsoft-visual-c-14/#i-2

シェアする

  • このエントリーをはてなブックマークに追加

フォローする