我一直在尝试使用
pip install
在Cygwin上安装
Python3.8下的
cython
和lxml
软件包。然而,这会反复失败,并出现难以理解的错误,从 python 错误到找不到 gcc 头文件,即使它们存在。
因为
lxml
取决于 Cython
,我们需要首先确保它可以工作。不幸的是Cygwin的python3.8似乎还不支持cython。因此我们被告知要从 here 下载并使用 wheel。
pip install Cython-0.29.13-cp38-cp38-win32.whl
# This fails with:
#ERROR: Cython-0.29.13-cp38-cp38-win32.whl is not a supported wheel on this platform.
# Instead use:
pip install Cython --install-option="--no-cython-compile"
# OK!
现在让我们尝试安装
lxml
软件包。
pip install lxml
# FAIL
STATIC_DEPS=true pip3 install lxml
# FAIL
让我们检查
Python.h
是否存在:
# find /usr/include -type f -name "Python.h"
/usr/include/python2.7/Python.h
/usr/include/python3.6m/Python.h
/usr/include/python3.8/Python.h
好的...
那么问题出在哪里呢?
相关问题:
唯一有效的方法是下载源代码并从那里安装。程序是这样的:
git clone https://github.com/lxml/lxml.git lxml
cd lxml
python3.8 setup.py install
pip-date |grep lxml
# lxml 2019-10-15 16:12:05 4.5.0a0 egg sdist sys
pip list |grep lxml
# lxml 4.5.0a0
编译失败的原因也可能是因为安装了多个gcc编译器。因此,虽然我还没有对此进行测试,但您可能需要指定(python?)环境应使用哪个编译器。
首先找到你的路径中有哪些编译器:
# ls -1 /usr/bin/*gcc.exe
/usr/bin/gcc.exe
/usr/bin/i686-w64-mingw32-gcc.exe
/usr/bin/x86_64-pc-cygwin-gcc.exe
/usr/bin/x86_64-w64-mingw32-gcc.exe
然后尝试将正确的变量导出到
CC
环境变量(例如):
export CC=/usr/bin/x86_64-w64-mingw32-gcc.exe
现在再次测试
pip install xxx
,看看是否有帮助。如果是这样,请将以上行添加到您的 ~/.bashrc
文件中。
您可以使用“setup-x86_64.exe”程序进行安装,如 Cygwin 官方文档 (https://cygwin.com/install.html) 中所述。安装程序可用于执行全新安装或更新现有安装。 实现这一目标的步骤: