0

Experiencing error Failed building wheel for lxml

src/lxml/etree.c:96:10: fatal error: 'Python.h' file not found #include "Python.h" ^~~~~~~~~~ 1 error generated.

ERROR: Could not build wheels for lxml, which is required to install pyproject.toml-based projects

while installing Scrapy

to install Scrapy in Pycharm

  • restart your system (computer), update it, then do a `pip install -U scrapy`. – Barry the Platipus Jun 02 '23 at 11:56
  • Hi Barry, Thank you for your response, However, it is still not resolved. To add more information I have a using Mac Ventura 13..4 version. Further, installed PyCharm Community Edition. Now it is showing Error. Error: Please make sure the libxml2 and libxslt development packages are installed. – Ayushi jain Jun 03 '23 at 16:23
  • OK, then do a `pip install -U pip`, then `pip install -U wheel`, then `pip install -U lxml`, then restart your computer. Are you on MacOS by any chance? – Barry the Platipus Jun 03 '23 at 16:25
  • Ok, if you will edit your message previous to my response, we cannot have a conversation. There are known issues with LXML on mac. See this question, for example: https://stackoverflow.com/questions/19548011/cannot-install-lxml-on-mac-os-x-10-9 – Barry the Platipus Jun 03 '23 at 16:52
  • Thank you Barry. Apologies for the editing. I am new to the Stack Overflow platform and was unaware that clicking return could add the comment. Because I was just wanting to go to the next line. Thank you the lxml has been installed with your given response. Thank you for your help. – Ayushi jain Jun 03 '23 at 19:41
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 04 '23 at 01:30

2 Answers2

0

I've run into the same issue recently while installing a package that depends on Scrapy, and I shared what helped me resolve the issue.

The lxml package seems to cause such errors when Xcode Command Line Tools are not correctly installed or some paths are missing/broken. As implied in your terminal, first try:

$ xcode-select --install

The command above will install the required packages if not installed already. If you receive the error xcode-select: error: command line tools are already installed, use "Software Update" to install updates, try resetting Xcode Command Line Tools as follows. It will reset the path to the Xcode Command Line Tools directory, which may help with the issue.

$ sudo xcode-select --reset

After you install/update Xcode Command Line Tools, try installing lxml separately to see if your issue is resolved.

$ pip install lxml
bkaankuguoglu
  • 1,192
  • 1
  • 13
  • 33
0

I was having the same problem and I simply installed XCode through the App Store (CLI was not sufficient). Seems to have fixed the problem for me!

archeezee
  • 411
  • 1
  • 4
  • 17