ImportError: no module named twisted.persisted.styles

From IDLE, I tried to run a script with the newly installed scrapy 1.0.3.

I am using a script from a friend he worked with (but on Windows I am on a Mac ).

From the scrapy import in the first line, I get this error when starting the program: ImportError: No module named twisted.persisted.styles

The whole script, if useful, points to the following:

 Traceback (most recent call last): File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module> import scrapy File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module> from . import _monkeypatches File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module> import twisted.persisted.styles # NOQA ImportError: No module named twisted.persisted.styles 

Any suggestions for resolving this issue?

+9
python scrapy macos
source share
4 answers

Just try forcibly updating twisted:

 pip install twisted --upgrade 

This works for me with python3.4 and Scrapy == 1.1.0rc1

+5
source share

Either twisted is installed on your mac (I doubt very much because it is not a standard library), and for some reason IDE (I assume that you mean since you typed "idle time"), or a terminal in which you do not have your updated environment variables, that is, it does not understand where your python libraries are by default (again, I doubt it very much), or you simply are not twisted on your Mac. If it is not installed, you have several options:

  • The easiest way to install the python package is pip .
  • If this is not an option, you can try homebrew , which is another package manager for mac. It offers an easy way to install packages correctly.
  • If this is not an option for you, or you simply do not want to try to download it directly from here (.bz2, since you are on a Mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the right place on your mac.
  • If this still doesn't work and you have decent unix knowledge. Use the "locate" command on the terminal and find out where your dist-packages directory is, and immediately drag the source file to twist into it, and then try to import the twisted IDE or python interpreter to make sure it is installed.

note . If you still have problems after installation, try restarting your IDE or using some settings to make sure your IDE has the correct environment and path to python. Hope this helps!

+1
source share

This may be due to installing Python without bzip2. I had the same error and it helped me, see the accepted answer here:

Twisted installation via pip does not work on one server

0
source share

This was in FreeBSD. Solution (as root / sudo):

chmod -R go+rX/usr/local/lib/python2.7/site-packages

Some directory permissions were not set directly during installation.

0
source share

All Articles