5

I'm new to python and I'm writing a simple TCP server Server.py, and I'm trying to import the reactor using this line of code from twisted.internet import reactor The problem is when I run the code I get this error

/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5     /Users/Nora/PycharmProjects/Server/Server.py
Traceback (most recent call last):
  File "/Users/Nora/PycharmProjects/Server/Server.py", line 2, in <module>
    from twisted.internet import reactor
ImportError: No module named 'twisted'

Note that I am using OS X Yosemite, and I have installed a new python version 3.5, how can I go back to the system built in version which already has twisted?

Nada
  • 97
  • 1
  • 7
  • run the program from the default python installation directory? – Pruthvi Raj Oct 21 '15 at 08:31
  • Are you install twisted? it's not basic. "pip install twisted" If you use python3.5, you can use asyncio to instead of twisted. It's better than twisted. Otherwise you use twisted in python2.x. – huang Oct 21 '15 at 09:22
  • I don't know that I would simply say asyncio is better then twisted, they are operating in different realms. Glyph covers this quite nicely in https://glyph.twistedmatrix.com/2014/05/the-report-of-our-death.html and the Autobahn (websocket lib) author in http://autobahn.ws/python/asynchronous-programming.html – Mike Lutz Oct 21 '15 at 13:49

1 Answers1

4

As xiaohen commented, twisted isn't in the standard python lib (It is installed on the internal OS X python by apple, but it won't automatically be available if you install a newer version of python).

pip install twisted will likely get you there.

BTW you might want to read and install the python virtualenv system before you install twisted so you'll know you can muck with your python libraries without having to worry about corrupting your core python load (Guides like http://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/ or http://michaelheap.com/virtualenv-and-pip-a-python-environment-in-60-seconds/ will help)

Community
  • 1
  • 1
Mike Lutz
  • 1,812
  • 1
  • 10
  • 17