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