在Python 2.7中安装和使用twill遇到问题

1 投票
1 回答
1058 浏览
提问于 2025-04-18 09:43

我通过pip安装了twill,然后又试着用easy_install安装。我想在PowerShell里玩玩它。根据这个页面 - http://twill.idyll.org/,我想试试它的功能。

要开始使用twill,先安装它,然后输入twill-sh。在提示符下输入:

go http://www.slashdot.org/
show
showforms
showhistory

但是当我输入twill-sh的时候,它不工作。我在PowerShell里输入过,加载了Python后试过,也在使用import twill后试过,但总是出现错误。

Traceback (most recent call last):
File "C:\Python27\Scripts\twill-sh-script.py", line 9, in <module>
load_entry_point('twill==1.8.0', 'console_scripts', 'twill-sh')()
File "build\bdist.win32\egg\pkg_resources.py", line 356, in load_entry_point
File "build\bdist.win32\egg\pkg_resources.py", line 2439, in load_entry_point
File "build\bdist.win32\egg\pkg_resources.py", line 2155, in load
File "C:\Python27\lib\site-packages\twill\__init__.py", line 52, in <module>
from shell import TwillCommandLoop
File "C:\Python27\lib\site-packages\twill\shell.py", line 9, in <module>
from twill import commands, parse, __version__
File "C:\Python27\lib\site-packages\twill\commands.py", line 7, in <module>
from lxml import html

我该怎么加载模块,这样我就可以在不写脚本的情况下玩它们呢?

1 个回答

0

我也遇到了同样的问题。在日志的后面,我发现了以下内容:

File "C:\Anaconda\lib\site-packages\lxml\cssselect.py", line 18, in <module> raise ImportError('cssselect seems not to be installed. '
ImportError: cssselect seems not to be installed. See http://packages.python.org/cssselect/

我通过安装一个叫做cssselect的包来解决这个问题(因为我使用的是Anaconda,所以我用conda来安装,pip也可以做到这一点)。

conda install cssselect

撰写回答