特别不建议在 python 3 中安装 pyspider 包括 python 3.5/3.6/3.7 有很多其他的问题,比如说
async
关键字的问题
首先安装 Python 2.7
版本,由于是 老旧版本,截至到 2024/11 最新的是 2.7.18 版本,可以参考 SF 介绍博客 The final Python 2 release marks the end of an era,可以使用 Pyenv/Virtualenv 单独安装一个,我这里用 Python 2.7.6 版本作为演示使用
注意:此处限制并且强烈推荐只使用 Python 2.7 版本!!!
# install python 2.7.6
pyenv install 2.7.6
# create python 2.7 virtualenv
pyenv virtualenv 2.7.6 venv27
# activate venv27
pyenv activate venv27
然后在该环境中安装 Pyspider 直接使用
# install pyspider
pip install pyspider
# run pyspider
pyspider all
第一次启动会报错,报错,错误信息 ValueError: Invalid configuration: - Deprecated option 'domaincontroller': use 'http_authenticator
此处替换 wsgidav == 2.4.1
版本即可解决该问题
pip uninstall wsgidav # 卸载
pip install wsgidav==2.4.1 # 安装2.4.1版本
第二次启动,报错,错误信息 mportError: cannot import name 'DispatcherMiddleware'
解决方法是 werkzeug 版本的原因,werkzeug 的版本为 1.0.0 这个版本中没有 DispatcherMiddleware
方法
注意:降低版本不能低于 0.15 版本,因为 pyspider 要求大于 0.15 版本以上
pip uninstall werkzeug # 卸载
pip install werkzeug==0.16.1 # 安装0.16.1版本
此时再次启动,应该就可以成功启动啦
附带正常在 Python 2.7.6 版本中安装 Pyspider 所有成功的依赖包列表如下
(venv27) ubuntu@debian:~$ pip install pyspider
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pyspider in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (0.3.10)
Requirement already satisfied: Jinja2>=2.7 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (2.11.3)
Requirement already satisfied: click>=3.3 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (7.1.2)
Requirement already satisfied: requests>=2.2 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (2.23.0)
Requirement already satisfied: chardet>=2.2 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (3.0.4)
Requirement already satisfied: Flask-Login>=0.2.11 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (0.5.0)
Requirement already satisfied: pycurl in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (7.43.0.5)
Requirement already satisfied: six>=1.5.0 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (1.14.0)
Requirement already satisfied: lxml in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (5.0.2)
Requirement already satisfied: cssselect>=0.9 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (1.1.0)
Requirement already satisfied: Flask>=0.10 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (1.1.4)
Requirement already satisfied: tornado<=4.5.3,>=3.2 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (4.5.3)
Requirement already satisfied: wsgidav in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (2.4.1)
Requirement already satisfied: tblib>=1.3.0 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (1.7.0)
Requirement already satisfied: pyquery in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (1.4.1)
Requirement already satisfied: u-msgpack-python>=1.6 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from pyspider) (2.8.0)
Requirement already satisfied: MarkupSafe>=0.23 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from Jinja2>=2.7->pyspider) (1.1.1)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from requests>=2.2->pyspider) (1.25.8)
Requirement already satisfied: certifi>=2017.4.17 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from requests>=2.2->pyspider) (2019.11.28)
Requirement already satisfied: idna<3,>=2.5 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from requests>=2.2->pyspider) (2.9)
Requirement already satisfied: itsdangerous<2.0,>=0.24 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from Flask>=0.10->pyspider) (1.1.0)
Requirement already satisfied: Werkzeug<2.0,>=0.15 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from Flask>=0.10->pyspider) (0.16.1)
Requirement already satisfied: singledispatch in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from tornado<=4.5.3,>=3.2->pyspider) (3.4.0.3)
Requirement already satisfied: backports-abc>=0.4 in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from tornado<=4.5.3,>=3.2->pyspider) (0.5)
Requirement already satisfied: defusedxml in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from wsgidav->pyspider) (0.7.1)
Requirement already satisfied: PyYAML in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from wsgidav->pyspider) (5.4.1)
Requirement already satisfied: jsmin in ./.pyenv/versions/2.7.17/envs/venv27/lib/python2.7/site-packages (from wsgidav->pyspider) (3.0.1)
WARNING: You are using pip version 20.0.2; however, version 20.3.4 is available.
You should consider upgrading via the '/home/vagrant/.pyenv/versions/2.7.17/envs/venv27/bin/python -m pip install --upgrade pip' command.
有依赖问题的同学,请参考上述版本处理自己的包依赖