Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named twisted.persisted.styles

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

I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).

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

The whole script, if it's helpful, points to this:

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 on how to tackle this problem?

like image 830
efong5 Avatar asked Nov 18 '15 05:11

efong5


Video Answer


2 Answers

Just try to force the update of twisted :

pip install twisted --upgrade

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

like image 162
Pierre Criulanscy Avatar answered Oct 17 '22 07:10

Pierre Criulanscy


Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:

  1. The easiest way to install a python package is through pip.
  2. If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
  3. If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're 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 correct location on your mac.
  4. If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.

note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!

like image 21
ihatecache Avatar answered Oct 17 '22 08:10

ihatecache