简体   繁体   English

如何在优胜美地设置lxml和pypy?

[英]How can I set up lxml and pypy on Yosemite?

I wanted to do some learning with lxml and pypy, so I decided to get it set up on my Yosemite Mac. 我想对lxml和pypy进行一些学习,因此我决定在Yosemite Mac上进行设置。 But after three days of trying, I still haven't been able to try lxml, because I can't get my setup right. 但是经过三天的尝试,我仍然无法尝试lxml,因为我无法正确设置我的设置。

Here's what I've done: 这是我所做的:

  1. Did a clean homebrew and xcode-select --install install 做了干净的homebrewxcode-select --install install

     proix:~ user$ brew --version 0.9.5 proix:~ user$ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix 
  2. Brewed up libxml2 and libxslt - libxml2 code tar 3.4.1 and libxslt code tar 1.1.28; 编译libxml2libxslt -libxml2代码tar 3.4.1和libxslt代码tar 1.1.28; worked fine. 工作正常。 Libs were built and installed. 库已构建并安装。

     proix:~ user$ brew list libxml2 libxslt proix:~ user$ brew info 2 kegs, 409 files, 14M proix:~ user$ ll /usr/local/Cellar/libxml2/2.9.2/lib/ total 6096 drwxr-xr-x 8 user admin 272 27 Dez 11:46 . drwxr-xr-x 13 user admin 442 27 Dez 11:46 .. drwxr-xr-x 3 user admin 102 27 Dez 11:46 cmake -r--r--r-- 1 user admin 1184284 27 Dez 11:46 libxml2.2.dylib -r--r--r-- 1 user admin 1922024 27 Dez 11:46 libxml2.a lrwxr-xr-x 1 user admin 15 27 Dez 11:46 libxml2.dylib -> libxml2.2.dylib drwxr-xr-x 3 user admin 102 27 Dez 11:46 pkgconfig -r--r--r-- 1 user admin 269 27 Dez 11:46 xml2Conf.sh proix:~ user$ ll /usr/local/Cellar/libxslt/1.1.28/lib/ total 1440 drwxr-xr-x 10 user admin 340 27 Dez 12:10 . drwxr-xr-x 13 user admin 442 27 Dez 12:10 .. -r--r--r-- 1 user admin 76728 27 Dez 12:10 libexslt.0.dylib -r--r--r-- 1 user admin 101832 27 Dez 12:10 libexslt.a lrwxr-xr-x 1 user admin 16 27 Dez 12:10 libexslt.dylib -> libexslt.0.dylib -r--r--r-- 1 user admin 214344 27 Dez 12:10 libxslt.1.dylib -r--r--r-- 1 user admin 326040 27 Dez 12:10 libxslt.a lrwxr-xr-x 1 user admin 15 27 Dez 12:10 libxslt.dylib -> libxslt.1.dylib drwxr-xr-x 4 user admin 136 27 Dez 12:10 pkgconfig -r--r--r-- 1 user admin 288 27 Dez 12:10 xsltConf.sh 
  3. But these new versions aren't being used: 但是并未使用这些新版本:

     $ xmllint --version xmllint: using libxml version 20900 
  4. So I switched the libs under /usr/lib via the Recovery console (cmd+R during boot). 因此,我通过故障恢复控制台(引导过程中为cmd + R)在/usr/lib下切换了libs。 After rebooting I get the expected result: 重新启动后,我得到了预期的结果:

     $ xmllint --version xmllint: using libxml version 20902` 

    A word of Warning! 一句话警告! Do not attempt to do this during a normal login session. 在正常的登录会话期间,请勿尝试执行此操作。 It utterly renders you system useless, if the OS cannot find libxml2.dylib any longer. 如果操作系统无法再找到libxml2.dylib ,它将完全使您的系统无用。

  5. Create a virtualenv for testing: 创建一个virtualenv进行测试:

     virtualenv lxmllab source lxmllab/bin/activate` 
  6. Install lxml with STATIC_DEPS=true sudo pip install lxml . 使用STATIC_DEPS=true sudo pip install lxml Worked fine as well: 也很好地工作:

     (lxmllab)proix:~ user$ pip list backports.ssl-match-hostname (3.4.0.2) certifi (14.5.14) cffi (0.6) docutils (0.12) ipython (2.3.1) Jinja2 (2.7.3) lxml (3.4.1) MarkupSafe (0.23) nose (1.3.4) numpydoc (0.5) pip (6.0.3) py (1.4.26) Pygments (2.0.1) pyzmq (14.4.1) setuptools (8.2.1) Sphinx (1.2.3) tornado (4.0.2) 
  7. Test it: 测试一下:

     (lxmllab)proix:~ user$ pypy -c 'from lxml import etree' Unknown libxml2 version: 20902 Traceback (most recent call last): File "app_main.py", line 72, in run_toplevel File "app_main.py", line 562, in run_it File "<string>", line 1, in <module> File "lxml.etree.pyx", line 270, in init lxml.etree (src/lxml/lxml.etree.c:199039) File "lxml.etree.pyx", line 235, in lxml.etree.__unpackDottedVersion (src/lxml/lxml.etree.c:9383) TypeError: unsupported operand type for int(): 'unicode' (lxmllab)proix:~ user$ pypy Python 2.7.3 (5acfe049a5b0, May 21 2013, 13:47:22) [PyPy 2.0.2 with GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: ``redefining yellow seems like a better idea'' ---- from lxml import etree Unknown libxml2 version: 20902 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "lxml.etree.pyx", line 270, in init lxml.etree (src/lxml/lxml.etree.c:199039) File "lxml.etree.pyx", line 235, in lxml.etree.__unpackDottedVersion (src/lxml/lxml.etree.c:9383) TypeError: unsupported operand type for int(): 'unicode' ---- 

That's where I got stuck. 那就是我被困住的地方。 I tried a couple of fixes, to no avail: 我尝试了几次修复,但无济于事:

  • Setting LD_LIBRARY_PATH and/or DYLD_LIBRARY_PATH to the locations of libxml2. LD_LIBRARY_PATH和/或DYLD_LIBRARY_PATH设置为libxml2的位置。
  • Copying the libxml2 dylibs to virtualenv site-packages/lxml folder. 将libxml2 dylib复制到virtualenv site-packages/lxml文件夹。

Does anybody know what I should do to get this to work, or what the correct way of getting the lxml lib working under Yosemite? 有人知道我应该怎么做才能使它工作,或者让lxml lib在优胜美地下工作的正确方法是什么?

PyPy does not work with lxml (at least not very well, even if it accidentally does), due to lxml being built on top of Cython which uses CPython C API bindings. 由于lxml是在使用CPython C API绑定的Cython之上构建的,因此PyPy无法与lxml一起使用(至少不是很好,即使它偶然地也不能)。 Consider using lxml-cffi instead https://github.com/amauryfa/lxml/tree/cffi 考虑使用lxml-cffi代替https://github.com/amauryfa/lxml/tree/cffi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM