How to Fix the "No module named 'cloudscraper'" Error in 3 Simple Steps

Aitor Mato
Aitor Mato
September 20, 2024 · 2 min read

Troubleshooting the No module named 'cloudscraper' error can seem like solving a mystery, especially when you're pretty sure you've installed the Cloudscraper package.

Fortunately, this is a common error that can be solved using the right approach.

In this guide, we'll walk you through three simple steps to resolve the issue.

Step 1: Verify Python Installation

First, ensure you're using the correct Python version.

If you have multiple Python versions installed (for example, 2.x and 3.x), it could result in the ModuleNotFoundError: No module named 'cloudscraper' error. You may have installed Cloudscraper for one version and tried to run it with the other.

Thus, verify your Python version by entering the following command in your terminal.

Terminal
python --version

This command will output your version, like in the example below.

Output
Python 3.12.4

If you get an error, it means you don't have Python installed or properly configured.

You can install Python using the command below.

Terminal
sudo apt-get update
sudo apt-get install -y python3.x # replace3.x with your desired Python version

For Windows and macOS, download the corresponding Python installer, run it, and follow the instructions.

Additionally, ensure you have pip, the Python package installer, available in your system's path. If you're running versions 3.4 and above, you most likely have this package by default.

To check if that's the case, run the following command if you're on a Linux or macOS system.

Terminal
command -v pip3

For Windows, use the where command.

Terminal
where pip3

If pip3 is installed and available in your system's path, the command above will output something like this.

Output
C:\Users\user\AppData\Local\Programs\Python\Python312\Scripts\pip3.exe

Otherwise, follow the instructions on the official pip installation guide page to install pip.

Step 2: Install the Cloudscraper Module

Install the Cloudscraper module using the following command:

Terminal
pip3 install cloudscraper

You may have Cloudscraper installed in one environment but not in the one you're using. A package must be explicitly available in an environment to function adequately.

Also, permissions can be a factor when installing or running Python packages. You might need to use sudo to install libraries globally on Unix-like systems, as this requires administrative privileges.

However, using sudo runs the command with root-level access to the system. For security reasons, it's best to use sudo only when necessary.

Virtual environments can help you with that, as you can fully use Python packages in the environment without granting elevated privileges. 

Step 3: Verify the Installation

Follow the steps below to verify your Cloudscraper installation.

Open a terminal and enter the command below to open the Python interpreter.

Terminal
python

In the Python interpreter, import Cloudscraper and hit Enter. If no error occurs, your installation works.

Terminal
import cloudscraper

You can run a test code to verify.

For this example, we'll make a quick request to an HTTPBin endpoint and print the response.

Example
import cloudscraper

# create CloudScraper instance
scraper = cloudscraper.create_scraper()  

# make a GET request
response = scraper.get("https://httpbin.io/ip")
print(response.text)

Here's the result.

Output
{
  "origin": "207.204.111.11:33090"
}

Congratulations! You've resolved the No module named 'Cloudscraper' error. 

Conclusion

Encountering the No module named 'cloudscraper' error when web scraping can be frustrating. Luckily, you can solve it using the following steps:

  • Verify your Python installation
  • Installing the Cloudscraper module correctly.

However, Cloudscraper might not be the best method to scrape the web in 2024, as anti-bot solutions can quickly detect its traffic. Check out this blog on Cloudscraper alternatives to discover simple-to-use but more advanced options.

Ready to get started?

Up to 1,000 URLs for free are waiting for you