【问题标题】:How to install lxml in Python 3.8 under Cygwin?如何在 Cygwin 下的 Python 3.8 中安装 lxml?
【发布时间】:2019-10-15 14:48:49
【问题描述】:

我一直在尝试使用pip installCygwin 上的Python3.8 下安装cythonlxml 软件包。然而,这反复失败,出现难以理解的错误,从 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

好的...

那么问题出在哪里?


相关问题:

【问题讨论】:

    标签: python cygwin lxml cython python-3.8


    【解决方案1】:

    似乎唯一可行的方法是下载源代码并从那里安装。程序是这样的:

    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 文件中。

    【讨论】:

      猜你喜欢
      • 2020-03-12
      • 2020-07-21
      • 2019-08-09
      • 1970-01-01
      • 2021-03-21
      • 2022-08-18
      • 2021-05-08
      • 1970-01-01
      • 2023-02-08
      相关资源
      最近更新 更多