2013-08-04 106 views
1

运行Python 2.7.5和OSX 10.8。还在使用Anaconda软件包管理器创建的虚拟env中运行Python。我已经安装了命令行工具的XCode 4.6.3。pip lxml安装分段错误

与scraperwiki例如瞎搞:

import scraperwiki 
html = scraperwiki.scrape('https://scraperwiki.com/hello_world.html') 
import lxml.cssselect 
import lxml.html 
root = lxml.html.fromstring(html) # turn our HTML into an lxml object 
tds = root.cssselect('td') # get all the <td> tags 
for td in tds: 
    print lxml.html.tostring(td) # the full HTML tag 
    print td.text    # just the text inside the HTML tag 

尝试使用lxml.cssselect引发此错误:

/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/lxml/cssselect.py in <module>() 
    16  external_cssselect = __import__('cssselect') 
    17 except ImportError: 
---> 18  raise ImportError('cssselect seems not to be installed. ' 
    19      'See http://packages.python.org/cssselect/') 
    20 

ImportError: cssselect seems not to be installed. See http://packages.python.org/cssselect/ 

使用IPython的,我找了安装的模块下LXML(打字LXML)和只找到lxml.etree和lxml.get_include:没有cssselect模块。

我尝试使用pip install lxml更新lxml --update。这还给:

Running setup.py egg_info for package lxml 
    /Users/mmoncrief/anaconda/envs/py27/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' 
     warnings.warn(msg) 
    Building lxml version 3.2.3. 
    Building without Cython. 
    Using build configuration of libxslt 1.1.28 
    Building against libxml2/libxslt in the following directory: /Users/mmoncrief/anaconda/envs/py27/lib 

    warning: no files found matching '*.txt' under directory 'src/lxml/tests' 
Downloading/unpacking update 
    Could not find any downloads that satisfy the requirement update 
No distributions at all found for update 
Storing complete log in /Users/mmoncrief/.pip/pip.log 

试图卸载LXML与PIP重新安装,我得到一个错误铿锵赛格故障。这里是部分来回pip.log:

/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url' 

    warnings.warn(msg) 

Building lxml version 3.2.3. 

Building without Cython. 

Using build configuration of libxslt 1.1.28 

Building against libxml2/libxslt in the following directory: /Users/mmoncrief/anaconda/envs/py27/lib 

running install 

running build 

running build_py 

copying src/lxml/includes/lxml-version.h -> build/lib.macosx-10.5-x86_64-2.7/lxml/includes 

running build_ext 

building 'lxml.etree' extension 

/usr/bin/clang -fno-strict-aliasing -I/Users/mmoncrief/anaconda/envs/py27/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/mmoncrief/anaconda/envs/py27/include -I/Users/mmoncrief/anaconda/envs/py27/include/libxml2 -I/private/var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-build-mmoncrief/lxml/src/lxml/includes -I/Users/mmoncrief/anaconda/envs/py27/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.5-x86_64-2.7/src/lxml/lxml.etree.o -flat_namespace 

clang: warning: argument unused during compilation: '-flat_namespace' 

src/lxml/lxml.etree.c:136455:17: warning: enumeration value '__pyx_e_4lxml_5etree_PARSER_DATA_INVALID' not handled in switch [-Wswitch] 

     switch (__pyx_v_doc_ref->_type) { 

       ^

src/lxml/lxml.etree.c:140541:72: warning: incompatible pointer types passing 'struct __pyx_obj_4lxml_5etree__BaseContext *' to parameter of type 'struct __pyx_obj_4lxml_5etree__XSLTContext *' [-Wincompatible-pointer-types] 

    __pyx_t_1 = ((PyObject *)__pyx_f_4lxml_5etree_12_XSLTContext__copy(((struct __pyx_obj_4lxml_5etree__BaseContext *)__pyx_v_self->_context))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 543; __pyx_clineno = __LINE__; goto __pyx_L9;} 

                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

src/lxml/lxml.etree.c:138476:138: note: passing argument to parameter '__pyx_v_self' here 

static struct __pyx_obj_4lxml_5etree__BaseContext *__pyx_f_4lxml_5etree_12_XSLTContext__copy(struct __pyx_obj_4lxml_5etree__XSLTContext *__pyx_v_self) { 

                                     ^

src/lxml/lxml.etree.c:141947:70: warning: incompatible pointer types passing 'struct __pyx_obj_4lxml_5etree__BaseContext *' to parameter of type 'struct __pyx_obj_4lxml_5etree__XSLTContext *' [-Wincompatible-pointer-types] 

    __pyx_t_1 = ((PyObject *)__pyx_f_4lxml_5etree_12_XSLTContext__copy(((struct __pyx_obj_4lxml_5etree__BaseContext *)__pyx_v_stylesheet->_context))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;} 

                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

src/lxml/lxml.etree.c:138476:138: note: passing argument to parameter '__pyx_v_self' here 

static struct __pyx_obj_4lxml_5etree__BaseContext *__pyx_f_4lxml_5etree_12_XSLTContext__copy(struct __pyx_obj_4lxml_5etree__XSLTContext *__pyx_v_self) { 

                                     ^

src/lxml/lxml.etree.c:160878:19: warning: expression result unused [-Wunused-value] 

    PyObject_INIT(o, t); 

       ^

/Users/mmoncrief/anaconda/envs/py27/include/python2.7/objimpl.h:164:69: note: expanded from macro 'PyObject_INIT' 

    (Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op)) 

                    ^

src/lxml/lxml.etree.c:162691:19: warning: expression result unused [-Wunused-value] 

    PyObject_INIT(o, t); 

       ^

/Users/mmoncrief/anaconda/envs/py27/include/python2.7/objimpl.h:164:69: note: expanded from macro 'PyObject_INIT' 

    (Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op)) 

                    ^

src/lxml/lxml.etree.c:168247:19: warning: expression result unused [-Wunused-value] 

    PyObject_INIT(o, t); 

       ^

/Users/mmoncrief/anaconda/envs/py27/include/python2.7/objimpl.h:164:69: note: expanded from macro 'PyObject_INIT' 

    (Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op)) 

                    ^

src/lxml/lxml.etree.c:170913:19: warning: expression result unused [-Wunused-value] 

    PyObject_INIT(o, t); 

       ^

/Users/mmoncrief/anaconda/envs/py27/include/python2.7/objimpl.h:164:69: note: expanded from macro 'PyObject_INIT' 

    (Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op)) 

                    ^

src/lxml/lxml.etree.c:12774:13: warning: function '__pyx_f_4lxml_5etree_displayNode' is not needed and will not be emitted [-Wunneeded-internal-declaration] 

static void __pyx_f_4lxml_5etree_displayNode(xmlNode *__pyx_v_c_node, PyObject *__pyx_v_indent) { 

      ^

8 warnings generated. 

/usr/bin/clang -bundle -undefined dynamic_lookup -L/Users/mmoncrief/anaconda/envs/py27/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/src/lxml/lxml.etree.o -L/Users/mmoncrief/anaconda/envs/py27/lib -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.5-x86_64-2.7/lxml/etree.so 

clang: error: unable to execute command: Segmentation fault: 11 

clang: error: linker command failed due to signal (use -v to see invocation) 

error: command '/usr/bin/clang' failed with exit status 254 

---------------------------------------- 

Command /Users/mmoncrief/anaconda/envs/py27/bin/python -c "import setuptools;__file__='/private/var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-build-mmoncrief/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-vTKUXu-record/install-record.txt --single-version-externally-managed failed with error code 1 in /private/var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-build-mmoncrief/lxml 

Exception information: 
Traceback (most recent call last): 
    File "/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/pip/basecommand.py", line 139, in main 
    status = self.run(options, args) 
    File "/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/pip/commands/install.py", line 271, in run 
    requirement_set.install(install_options, global_options, root=options.root_path) 
    File "/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/pip/req.py", line 1185, in install 
    requirement.install(install_options, global_options, *args, **kwargs) 
    File "/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/pip/req.py", line 592, in install 
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False) 
    File "/Users/mmoncrief/anaconda/envs/py27/lib/python2.7/site-packages/pip/util.py", line 662, in call_subprocess 
    % (command_desc, proc.returncode, cwd)) 
InstallationError: Command /Users/mmoncrief/anaconda/envs/py27/bin/python -c "import setuptools;__file__='/private/var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-build-mmoncrief/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-vTKUXu-record/install-record.txt --single-version-externally-managed failed with error code 1 in /private/var/folders/l2/zvz4t5rs7pb3n1bc4_bdz6n4cbzgwl/T/pip-build-mmoncrief/lxml 

任何帮助非常感谢!

+0

在OSX上我有过卢布从pip安装lxml。 easy_install似乎工作得更好,但最重要的是直接下载代码并运行python setup.py install – synthesizerpatel

回答

2

注意错误消息:

ImportError: cssselect seems not to be installed. See http://packages.python.org/cssselect/


cssselect已被移动到成为一个单独的包。试着用

pip install cssselect 
+0

,虽然我也更新了anaconda分布式的lxml,所以我不确定哪个技巧。非常感谢。 – user2651369

+0

尽管如此,clang错误仍然存​​在。例如,试图安装需要lxml的Scrapy,会导致相同的clang错误。 – user2651369