9

So they removed the cssselect package from lxml.. Now my python program is useless. I just can't figure out how I could get it working:

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

I've tried to copy cssselect directory to my code directory -> solves the error when compiling bytecode files, but when running the program, the error persists.

I've tried to rewrite my lxml.cssselect commands but no result.

I've searched the whole internet, but without an answer.

now I just have line:

from lxml.html import parse

and the code that uses cssselect is

inner = html.xpath('//*[@id="Content..."]')
for b in inner:
...
  for a in b.cssselect('p'):
  ...

So either how to import it so the original code works? Do I need to manually copy it to some place or what?

or how to find/replace the code to get it working?

(oh and a note, ofc I've installed both lxml and cssselect packages)

kamilla
  • 361
  • 1
  • 3
  • 8
  • 3
    You searched the **whole** internet? A bold statement ;) – dirkk Apr 22 '14 at 15:19
  • Newer `lxml` do indeed import cssselect as external (https://github.com/lxml/lxml/blob/master/src/lxml/cssselect.py#L16). You shouldn't need to copy or rewrite `lxml.cssselect`. Installing `cssselect` is sufficient. What does `import cssselect` in a Python shell give you? – paul trmbrth Apr 22 '14 at 16:39
  • 2
    @dirkk Searching the whole internet is unfortunately necessary when it comes to figuring out how to wrangle lxml into working. something like BeatifulSoup wouldn't be necessary (let alone popular) if lxml were intuitive to begin with – Alkanshel Nov 30 '14 at 23:15

2 Answers2

14

The problem was with the cssselect installation. For some unidentified reason the cssselect package was installed to /root/.local/lib/python2.7/site-packages/ instead of /usr/local/lib/python2.7/dist-packages/.

Cssselect was installed with pip install cssselect on Debian GNU/Linux 7.4 (wheezy, Linux 3.2.0-4-amd64 x86_64). Don't know if it was just some weird typo of mine, or a bug.

The solution was to uninstall cssselect and reinstall it. This time it went to correct place and everything works as before. There was no need to modify python code at all.

Ty, for you answers ;)

kamilla
  • 361
  • 1
  • 3
  • 8
5

My solution was to install cssselect using pip3:

sudo pip3 install cssselect
Sérgio
  • 51
  • 1
  • 1