Installation guide

Installing Scrapy

Scrapy runs on Python 2.7 and Python 3.3 or above (except on Windows where Python 3 is not supported yet).

If you’re already familiar with installation of Python packages, you can install Scrapy and its dependencies from PyPI with:

pip install Scrapy

We strongly recommend that you install Scrapy in a dedicated virtualenv, to avoid conflicting with your system packages.

For more detailed and platform specifics instructions, read on.

Things that are good to know

Scrapy is written in pure Python and depends on a few key Python packages (among others):

  • lxml, an efficient XML and HTML parser
  • parsel, an HTML/XML data extraction library written on top of lxml,
  • w3lib, a multi-purpose helper for dealing with URLs and web page encodings
  • twisted, an asynchronous networking framework
  • cryptography and pyOpenSSL, to deal with various network-level security needs

The minimal versions which Scrapy is tested against are:

  • Twisted 14.0
  • lxml 3.4
  • pyOpenSSL 0.14

Scrapy may work with older versions of these packages but it is not guaranteed it will continue working because it’s not being tested against them.

Some of these packages themselves depends on non-Python packages that might require additional installation steps depending on your platform. Please check platform-specific guides below.

In case of any trouble related to these dependencies, please refer to their respective installation instructions:

Platform specific installation notes

Windows

  • Install Python 2.7 from https://www.python.org/downloads/

    You need to adjust PATH environment variable to include paths to the Python executable and additional scripts. The following paths need to be added to PATH:

    C:\Python27\;C:\Python27\Scripts\;
    

    To update the PATH open a Command prompt and run:

    c:\python27\python.exe c:\python27\tools\scripts\win_add2path.py
    

    Close the command prompt window and reopen it so changes take effect, run the following command and check it shows the expected Python version:

    python --version
    
  • Install pywin32 from http://sourceforge.net/projects/pywin32/

    Be sure you download the architecture (win32 or amd64) that matches your system

  • (Only required for Python<2.7.9) Install pip from https://pip.pypa.io/en/latest/installing/

    Now open a Command prompt to check pip is installed correctly:

    pip --version
    
  • At this point Python 2.7 and pip package manager must be working, let’s install Scrapy:

    pip install Scrapy
    

Note

Python 3 is not supported on Windows. This is because Scrapy core requirement Twisted does not support Python 3 on Windows.

Ubuntu 12.04 or above

Scrapy is currently tested with recent-enough versions of lxml, twisted and pyOpenSSL, and is compatible with recent Ubuntu distributions. But it should support older versions of Ubuntu too, like Ubuntu 12.04, albeit with potential issues with TLS connections.

Don’t use the python-scrapy package provided by Ubuntu, they are typically too old and slow to catch up with latest Scrapy.

To install scrapy on Ubuntu (or Ubuntu-based) systems, you need to install these dependencies:

sudo apt-get install python-dev python-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
  • python-dev, zlib1g-dev, libxml2-dev and libxslt1-dev are required for lxml
  • libssl-dev and libffi-dev are required for cryptography

If you want to install scrapy on Python 3, you’ll also need Python 3 development headers:

sudo apt-get install python3 python3-dev

Inside a virtualenv, you can install Scrapy with pip after that:

pip install scrapy

Note

The same non-python dependencies can be used to install Scrapy in Debian Wheezy (7.0) and above.

Mac OS X

Building Scrapy’s dependencies requires the presence of a C compiler and development headers. On OS X this is typically provided by Apple’s Xcode development tools. To install the Xcode command line tools open a terminal window and run:

xcode-select --install

There’s a known issue that prevents pip from updating system packages. This has to be addressed to successfully install Scrapy and its dependencies. Here are some proposed solutions:

  • (Recommended) Don’t use system python, install a new, updated version that doesn’t conflict with the rest of your system. Here’s how to do it using the homebrew package manager:

    • Install homebrew following the instructions in http://brew.sh/

    • Update your PATH variable to state that homebrew packages should be used before system packages (Change .bashrc to .zshrc accordantly if you’re using zsh as default shell):

      echo "export PATH=/usr/local/bin:/usr/local/sbin:$PATH" >> ~/.bashrc
      
    • Reload .bashrc to ensure the changes have taken place:

      source ~/.bashrc
      
    • Install python:

      brew install python
      
    • Latest versions of python have pip bundled with them so you won’t need to install it separately. If this is not the case, upgrade python:

      brew update; brew upgrade python
      
  • (Optional) Install Scrapy inside an isolated python environment.

    This method is a workaround for the above OS X issue, but it’s an overall good practice for managing dependencies and can complement the first method.

    virtualenv is a tool you can use to create virtual environments in python. We recommended reading a tutorial like http://docs.python-guide.org/en/latest/dev/virtualenvs/ to get started.

After any of these workarounds you should be able to install Scrapy:

pip install Scrapy

Anaconda

Using Anaconda is an alternative to using a virtualenv and installing with pip.

Note

For Windows users, or if you have issues installing through pip, this is the recommended way to install Scrapy.

If you already have Anaconda or Miniconda installed, the conda-forge community have up-to-date packages for Linux, Windows and OS X.

To install Scrapy using conda, run:

conda install -c conda-forge scrapy