没有名为lxml.html的模块

时间:2014-08-10 01:16:18

标签: python python-2.7 scrapy pip lxml

运行OS X 10.9.4,我正在尝试使用Scrapy,但是我收到了这个错误:

Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 3, in <module>
from scrapy.cmdline import execute
File "/Library/Python/2.7/site-packages/scrapy/cmdline.py", line 8, in <module>
from scrapy.crawler import CrawlerProcess
File "/Library/Python/2.7/site-packages/scrapy/crawler.py", line 6, in <module>
from scrapy.core.engine import ExecutionEngine
File "/Library/Python/2.7/site-packages/scrapy/core/engine.py", line 14, in <module>
from scrapy.core.downloader import Downloader
File "/Library/Python/2.7/site-packages/scrapy/core/downloader/__init__.py", line 13, in <module>
from .middleware import DownloaderMiddlewareManager
File "/Library/Python/2.7/site-packages/scrapy/core/downloader/middleware.py", line 7, in <module>
from scrapy.http import Request, Response
File "/Library/Python/2.7/site-packages/scrapy/http/__init__.py", line 11, in <module>
from scrapy.http.request.form import FormRequest
File "/Library/Python/2.7/site-packages/scrapy/http/request/form.py", line 9, in <module>
import lxml.html

'pip install lxml'只返回

/Users/username/.virtualenvs/scraper/lib/python2.7/site-packages

1 个答案:

答案 0 :(得分:3)

好像你用系统版本的Python安装了scrapy

在virtualenv版本的Python中安装了lxml

使用以下命令检查pip参考哪个python:

pip -V

如果您想在virtualenv中安装scapy,则需要先卸载scrapy。否则,由于PATH问题,它将阻止virtualenv版本的运行。

deactive  # deactive first, to use system version of python/pip
pip uninstall -y scrapy
hash -r   # refresh program location.