2

Python 2.7.5 および OSX 10.8 を実行しています。また、Anaconda パッケージ マネージャーで作成された仮想環境で Python を実行しています。コマンド ライン ツールがインストールされた XCode 4.6.3 があります。

スクレイパーウィキの例をいじります:

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 --update を使用して lxml を更新しようとしました。これにより、次のことが返されます。

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 で再インストールしようとすると、clang エラーと seg fault が発生します。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

どんな助けでも大歓迎です!

4

2 に答える 2

2

エラー メッセージに注意してください。

ImportError: cssselect がインストールされていないようです。http://packages.python.org/cssselect/を参照してください 。


cssselect別のパッケージになるように移動されました。でインストールしてみてください

pip install cssselect
于 2013-08-04T23:34:57.867 に答える
0

次の方法でlxmlをインストールする代わりに、これは私にとってはうまくいきました:

pip install lxml

試す:

$CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 pip install -U lxml

ここにある解決策: http://unflyingobject.com/blog/stories/installing-lxml-on-109/

于 2015-06-23T03:20:44.770 に答える