Scrapy 简明教程
Scrapy - Environment
在本章中,我们将讨论如何安装和设置 Scrapy。Scrapy 必须与 Python 一起安装。
In this chapter, we will discuss how to install and set up Scrapy. Scrapy must be installed with Python.
可以通过 pip 安装 Scrapy。要安装,运行以下命令 −
Scrapy can be installed by using pip. To install, run the following command −
pip install Scrapy
Windows
Note - 在 Windows 操作系统上不支持 Python 3。
Note − Python 3 is not supported on Windows OS.
Step 1 - 从 Python 安装 Python 2.7
Step 1 − Install Python 2.7 from Python
通过将以下路径添加到 PATH 来设置环境变量 −
Set environmental variables by adding the following paths to the PATH −
C:\Python27\;C:\Python27\Scripts\;
你可以使用以下命令来检查 Python 版本 −
You can check the Python version using the following command −
python --version
Step 2 - 安装 OpenSSL 。
Step 2 − Install OpenSSL.
在你的环境变量中添加 C:\OpenSSL-Win32\bin。
Add C:\OpenSSL-Win32\bin in your environmental variables.
Note - OpenSSL 预装在除 Windows 以外的所有操作系统中。
Note − OpenSSL comes preinstalled in all operating systems except Windows.
Step 3 - 安装 Visual C++ 2008 再发行包。
Step 3 − Install Visual C++ 2008 redistributables.
Step 4 - 安装 pywin32 。
Step 4 − Install pywin32.
Step 5 - 为早于 2.7.9 的 Python 安装 pip 。
Step 5 − Install pip for Python versions older than 2.7.9.
你可以使用下面的命令检查 pip 版本 -
You can check the pip version using the following command −
pip --version
Step 6 - 要安装 scrapy,运行以下命令 -
Step 6 − To install scrapy, run the following command −
pip install Scrapy
Anaconda
If you have anaconda or miniconda installed on your machine, run the below command to install Scrapy using conda −
conda install -c scrapinghub scrapy
Scrapinghub 公司支持 Linux、Windows 和 OS X 的官方 conda 包。
Scrapinghub company supports official conda packages for Linux, Windows, and OS X.
Note - 如果你在使用 pip 安装时遇到问题,建议通过上面的命令安装 Scrapy。
Note − It is recommended to install Scrapy using the above command if you have issues installing via pip.
Ubuntu 9.10 or Above
最新版的 Python 已预先安装在 Ubuntu 操作系统上。使用由 Scrapinghub 提供的 Ubuntu 包 aptgettable。要使用这些包 -
The latest version of Python is pre-installed on Ubuntu OS. Use the Ubuntu packages aptgettable provided by Scrapinghub. To use the packages −
Step 1 - 你需要将用于对 Scrapy 包进行签名的 GPG 密钥导入 APT 密钥环 -
Step 1 − You need to import the GPG key used to sign Scrapy packages into APT keyring −
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 627220E7
Step 2 - 接下来,使用下面的命令创建 /etc/apt/sources.list.d/scrapy.list 文件 -
Step 2 − Next, use the following command to create /etc/apt/sources.list.d/scrapy.list file −
echo 'deb http://archive.scrapy.org/ubuntu scrapy main' | sudo tee
/etc/apt/sources.list.d/scrapy.list
Step 3 - 更新包列表并安装 scrapy -
Step 3 − Update package list and install scrapy −
sudo apt-get update && sudo apt-get install scrapy
Archlinux
你可以使用下面的命令从 AUR Scrapy 包安装 Scrapy -
You can install Scrapy from AUR Scrapy package using the following command −
yaourt -S scrapy
Mac OS X
使用下面的命令安装 Xcode 命令行工具 -
Use the following command to install Xcode command line tools −
xcode-select --install
安装一个新的更新版本而不是使用系统 Python,该版本不会与系统中的其他部分发生冲突。
Instead of using system Python, install a new updated version that doesn’t conflict with the rest of your system.
Step 1 - 安装 homebrew 。
Step 1 − Install homebrew.
Step 2 - 设置环境 PATH 变量,以指定 homebrew 包应在系统包之前使用 -
Step 2 − Set environmental PATH variable to specify that homebrew packages should be used before system packages −
echo "export PATH = /usr/local/bin:/usr/local/sbin:$PATH" >> ~/.bashrc
Step 3 - 要确保已经完成更改,使用以下命令重新加载 .bashrc -
Step 3 − To make sure the changes are done, reload .bashrc using the following command −
source ~/.bashrc
Step 4 - 接下来,使用下面的命令安装 Python -
Step 4 − Next, install Python using the following command −
brew install python
Step 5 - 使用下面的命令安装 Scrapy -
Step 5 − Install Scrapy using the following command −
pip install Scrapy