仅使用 python 包在 OpenShift 上安装 lxml(pip,easy_install)

Install lxml on OpenShift with python packages only (pip, easy_install)

我在我的 Django 应用程序 (python 2.7) 中使用 Beautifulsoup 和 lxml 包。我的生产服务器是 OpenShift,因此由于访问权限,我无法使用 apt-get 安装。过去我能够使用 easy_install 将 lxml 安装到 OpenShift,但我现在很难这样做。
好吧,我可能遗漏了一些通过 apt-get 安装的依赖项,例如 these?
我试图通过将 lxml 添加到我的 setup.py 文件来安装 lxml。没用。
所以我尝试了 pip install lxml==3:

> pip install lxml==3
Downloading/unpacking lxml==3
  Downloading lxml-3.0.tar.gz (3.2MB): 3.2MB downloaded
  Running setup.py egg_info for package lxml
    Building lxml version 3.0.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib64

    warning: no previously-included files found matching '*.py'
    warning: no files found matching '*.txt' under directory 'src/lxml/tests'
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 3.0.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib64
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/libxml2 -I/var/lib/openshift/569eccb30c1e661fc20000d5/app-root/runtime/dependencies/python/virtenv/build/lxml/src/lxml/includes -I/opt/rh/python27/root/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o
    src/lxml/lxml.etree.c: In function ‘__pyx_pf_4lxml_5etree_4XSLT_18__call__’:
    src/lxml/lxml.etree.c:132418: warning: passing argument 1 of ‘__pyx_f_4lxml_5etree_12_XSLTContext__copy’ from incompatible pointer type
    src/lxml/lxml.etree.c:130379: note: expected ‘struct __pyx_obj_4lxml_5etree__XSLTContext *’ but argument is of type ‘struct __pyx_obj_4lxml_5etree__BaseContext *’
    src/lxml/lxml.etree.c: In function ‘__pyx_f_4lxml_5etree__copyXSLT’:
    src/lxml/lxml.etree.c:133807: warning: passing argument 1 of ‘__pyx_f_4lxml_5etree_12_XSLTContext__copy’ from incompatible pointer type
    src/lxml/lxml.etree.c:130379: note: expected ‘struct __pyx_obj_4lxml_5etree__XSLTContext *’ but argument is of type ‘struct __pyx_obj_4lxml_5etree__BaseContext *’
    src/lxml/lxml.etree.c: At top level:
    src/lxml/lxml.etree.c:11938: warning: ‘__pyx_f_4lxml_5etree_displayNode’ defined but not used
Connection to app-nick.rhcloud.com closed by remote host.
Connection to app-nick.rhcloud.com closed.

如果我用 pip 指定 subversion(3.4 而不是 3),输出会有点不同:

pip install lxml==3.4
Downloading/unpacking lxml==3.4
  Downloading lxml-3.4.0.tar.gz (3.5MB): 3.5MB downloaded
  Running setup.py egg_info for package lxml
    /opt/rh/python27/root/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.4.0.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib64

    warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
  Running setup.py install for lxml
    /opt/rh/python27/root/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.4.0.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib64
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/libxml2 -I/var/lib/openshift/569eccb30c1e661fc20000d5/app-root/runtime/dependencies/python/virtenv/build/lxml/src/lxml/includes -I/opt/rh/python27/root/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w

和easy_install:

> easy_install lxml
Searching for lxml
Reading https://pypi.python.org/simple/lxml/
Best match: lxml 3.5.0
Downloading https://pypi.python.org/packages/source/l/lxml/lxml-3.5.0.tar.gz#md5=9f0c5f1eb43ff44d5455dab4b4efbe73
Processing lxml-3.5.0.tar.gz
Writing /tmp/easy_install-K7xT2d/lxml-3.5.0/setup.cfg
Running lxml-3.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-K7xT2d/lxml-3.5.0/egg-dist-tmp-BAe44x
Building lxml version 3.5.0.
Building without Cython.
Using build configuration of libxslt 1.1.26
Building against libxml2/libxslt in the following directory: /usr/lib64
Connection to app-nick.rhcloud.com closed by remote host.
Connection to app-nick.rhcloud.com closed.

如何通过 pip 或仅 easy_install 安装 lxml? 或者我应该使用另一个 xml 解析器和 BeautifulSoup(不确定是否有其他选择)?


更新1

我尝试安装 lxml==3.2.5。我忘了说我在 python 2.7 档位。如果我将 , 'lxml==3.2.5' 添加到我的 setup.py 文件中(我认为 setup.py 与 requirements.txt 的工作方式相同),这是输出:

remote: Searching for lxml==3.2.5
remote: Reading http://mirror1.ops.rhcloud.com/mirror/python/web/simple/lxml/
remote: Best match: lxml 3.2.5
remote: Downloading http://mirror1.ops.rhcloud.com/mirror/python/web/packages/source/l/lxml/lxml-3.2.5.tar.gz#md5=6c4fb9b1840631cff09b8229a12a9ef7
remote: Processing lxml-3.2.5.tar.gz
remote: Writing /tmp/easy_install-jvJHz8/lxml-3.2.5/setup.cfg
remote: Running lxml-3.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-jvJHz8/lxml-3.2.5/egg-dist-tmp-KMpa_f
remote: /opt/rh/python27/root/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
remote:   warnings.warn(msg)
remote: warning: no files found matching '*.txt' under directory 'src/lxml/tests'
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_11TreeBuilder_4data':
remote: src/lxml/lxml.etree.c:97814: warning: passing argument 1 of '__pyx_f_4lxml_5etree_11TreeBuilder__handleSaxData' from incompatible pointer type
remote: src/lxml/lxml.etree.c:97415: note: expected 'struct __pyx_obj_4lxml_5etree_TreeBuilder *' but argument is of type 'struct __pyx_obj_4lxml_5etree__SaxParserTarget *'
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_11TreeBuilder_6start':
remote: src/lxml/lxml.etree.c:97951: warning: passing argument 1 of '__pyx_f_4lxml_5etree_11TreeBuilder__handleSaxStart' from incompatible pointer type
remote: src/lxml/lxml.etree.c:97115: note: expected 'struct __pyx_obj_4lxml_5etree_TreeBuilder *' but argument is of type 'struct __pyx_obj_4lxml_5etree__SaxParserTarget *'
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_11TreeBuilder_8end':
remote: src/lxml/lxml.etree.c:98009: warning: passing argument 1 of '__pyx_f_4lxml_5etree_11TreeBuilder__handleSaxEnd' from incompatible pointer type
remote: src/lxml/lxml.etree.c:97339: note: expected 'struct __pyx_obj_4lxml_5etree_TreeBuilder *' but argument is of type 'struct __pyx_obj_4lxml_5etree__SaxParserTarget *'
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_11TreeBuilder_10pi':
remote: src/lxml/lxml.etree.c:98167: warning: passing argument 1 of '__pyx_f_4lxml_5etree_11TreeBuilder__handleSaxPi' from incompatible pointer type
remote: src/lxml/lxml.etree.c:97455: note: expected 'struct __pyx_obj_4lxml_5etree_TreeBuilder *' but argument is of type 'struct __pyx_obj_4lxml_5etree__SaxParserTarget *'
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_11TreeBuilder_12comment':
remote: src/lxml/lxml.etree.c:98220: warning: passing argument 1 of '__pyx_f_4lxml_5etree_11TreeBuilder__handleSaxComment' from incompatible pointer type
remote: src/lxml/lxml.etree.c:97581: note: expected 'struct __pyx_obj_4lxml_5etree_TreeBuilder *' but argument is of type 'struct __pyx_obj_4lxml_5etree__SaxParserTarget *'
remote: src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__xslt_resolve_from_python':
remote: src/lxml/lxml.etree.c:136117: warning: enumeration value '__pyx_e_4lxml_5etree_PARSER_DATA_INVALID' not handled in switch
remote: src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__':
remote: src/lxml/lxml.etree.c:140191: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type
remote: src/lxml/lxml.etree.c:138126: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
remote: src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':
remote: src/lxml/lxml.etree.c:141589: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type
remote: src/lxml/lxml.etree.c:138126: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
Connection to app-host.rhcloud.com closed by remote host.
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer

更新2 我尝试安装 Cython (pip install cython),它也失败了 -> 我与 OpenShift 断开连接。
我在 RedHat's bugzilla.

中创建了错误报告

奇怪的错误,RedHat 的 Maciej 建议我从头开始重新创建 Openshift 应用程序。它工作正常,我能够成功安装 lxml。

对于 UPDATE1 症状,除了没有在 requirements.txt 中给出版本号,因为它是我正在使用的另一个库的依赖项,这为我修复了它:

  1. rhc ssh申请
  2. 运行 pip install lxml
  3. 运行 pip install lxml 再一次

在第 2 步之后。(第一个 pip 运行)输出为:

Downloading/unpacking lxml

pip can't proceed with requirement 'lxml' due to a pre-existing build directory.
 location: /var/lib/openshift/xxx/app-root/runtime/dependencies/python/virtenv/build/lxml
This is likely due to a previous installation that failed.
pip is being responsible and not assuming it can delete this.
Please delete it and try again.

Cleaning up...

第二个 pip 运行 成功完成,不需要删除 pip 建议的目录(也不存在)。

pip 正在使用 lxml 版本 3.6.0 - python 2.7 作为墨盒。