Python3 error No module named 'attrs' when running Scrapy in Ubuntu terminal


I am new to Python. I installed Scrapy on ubuntu linux. When I run Scrapy shell I get this error

  File "/home/user/.local/lib/python3.10/site-packages/scrapy/downloadermiddlewares/", line 25, in <module>
from twisted.web.client import ResponseFailed
File "/home/user/.local/lib/python3.10/site-packages/twisted/web/", line 24, in <module>
from twisted.internet.endpoints import HostnameEndpoint, wrapClientTLS
File "/home/user/.local/lib/python3.10/site-packages/twisted/internet/", line 63, in <module>
from twisted.python.systemd import ListenFDs
File "/home/user/.local/lib/python3.10/site-packages/twisted/python/", line 18, in <module>
from attrs import Factory, define
ModuleNotFoundError: No module named 'attrs'

I also already ran the commands

python3.10 -m pip install attrs
pip install attrs

with the result

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: attrs in /usr/lib/python3/dist-packages (21.2.0)

Asked By: M a m a D



few days ago i was also facing same issue while trying to run my scraper spider on linux server then i figured it out by running my scrapy spider inside an virtual environment. Hopefully it will also work for you.:)

Answered By: Muhammad Fahim

For me what worked was to uninstall scrapy and attrs (pip uninstall scrapy attrs) and reinstalling scrapy. I didn’t have to re-install attrs because scrapy ships with it’s own version of attrs.

Answered By: Ramy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.