Install TextAttack on Windows

Source: Giuseppe Murro

Hi everyone! I’ve been struggling with the installation of a very good python library called TextAttack (https://github.com/QData/TextAttack) since its setup is not so straightforward on a Windows machine. I’m sharing this with the hope of saving your time!

Requirements

1. Install MSVC compiler

First of all, you need to install a compiler for the C, C++ and C++/CX programming languages for Windows. The simplest way is through Visual Studio Community 2019 Installer, selecting the Desktop development with C++ box. A reboot could be needed after the installation.

2. Create a conda environment

Using Anaconda to create dedicated environments is always the best way to not mess up your python installation. Run the following commands in a terminal:

conda create -n textattack python=3.8
conda activate textattack

3. Install PyCLD2

On Windows the installation of TextAttack cannot build the library pycld2 automatically, so you need to install it from unofficial windows binaries.

In the PyCL2 section, there are several files, where “cp**” indicates the python version (e.g. cp38 stands for python 3.8). If you have a 64-bit Windows system, you have to download the file coloured in red.

To install it, run the following command in the same terminal as before:

cd Downloads
pip install pycld2-0.41-cp39-cp39-win\_amd64.whl

4. Install TextAttack

Now you can proceed to install the TextAttack library:

pip install textattack

5. CUDA Acceleration

Now everything is setted up and you can start your coding session.

But in order to speed up the performance of TextAttack, you need to install both Tensorflow and Pytorch with CUDA compatibility if you have a NVIDIA GPU. My advice is to install the most recent CUDA version which is supported by both Tensorflow and Pytorch (according to the official tf and torch docs the newest version like 11.2 or 11.3 are not compatible with both). This is CUDA 11.0 and you can follow this guide.

Then if CUDA 11.0 is installed correctly (check with nvcc -V` command), install Tensorflow and Pytorch on our conda environment with the following commands:

pip install tensorflow==2.4
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html