Search code examples
pythonmacostwisted

how to setup twist 14.0.0 for Python 2.7.8


I am following a tutorial on communicate TCP using twisted with Python. When I ran my code module it failed on the first line:

ImportError: No module named twisted.internet.protocol

So I guess there is no twisted install with my current of python 2.7.8. I am using Mac OS X 10.9.8.

So I tried to install twisted and version I found is tarball 14.0.0.
I install from terminal with command line:

sudo python setup.py install.

And everything look OK to me.

Now I ran the code module and I still have the same error. I guess I need to configure the new install twisted with python. I am looking for a guidance but still no luck yet.


Solution

  • When you ran:

    sudo python setup.py install
    

    You may well have screwed up your system.

    setup.py install scribbles random files onto random pieces of your filesystem. Your OS maintainer has certain ideas about what files should exist in the "system" part of your system - loosely speaking, the part outside of the "home directory" area. When you run setup.py install using sudo you give it permission to write files of this "system" area. There's a reason normal users aren't allowed to write files there.

    Perhaps some critical system service depends on a certain version of a Python library and this sudo python setup.py install command replaces the installed version (the version that your OS maintainer installed and shipped to you) with a different, incompatible version.

    Or perhaps it's not a critical system service, maybe it's just one of the programs you use from time to time. Either way, it's now broken.

    Never, never, never, never, never run that command. It doesn't matter what package you're thinking about installing: this is the wrong way to install it.

    You should probably wipe your host and do a fresh install of your OS. Unfortunately this drastic solution is the most straightforward. setup.py install does not keep a record of what files it wrote or where. You can try to undo whatever damage it did, but figuring out what that damage is is complicated (beyond the scope of this answer) and time-consuming.

    Then, install virtualenv and/or virtualenv wrapper. Then create a virtual environment, activate it, and install the desired Python packages into the environment.

    virtualenv gives you isolated Python environments that don't interfere with each other or with your system Python. You can have as many of them as you want. They're cheap to create and if things go wrong you can easily destroy them and start over again.

    Here's what the process looks like on Linux:

    exarkun@top:/tmp$ virtualenv virtualenv-demo
    New python executable in virtualenv-demo/bin/python
    Installing setuptools, pip...done.
    exarkun@top:/tmp$ . virtualenv-demo/bin/activate
    (virtualenv-demo)exarkun@top:/tmp$ pip install twisted
    Downloading/unpacking twisted
      Using download cache from /home/exarkun/.pip/download-cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FT%2FTwisted%2FTwisted-14.0.0.tar.bz2
      Running setup.py (path:/tmp/virtualenv-demo/build/twisted/setup.py) egg_info for package twisted
    
    Downloading/unpacking zope.interface>=3.6.0 (from twisted)
    .
    .
    .
    Installing /tmp/virtualenv-demo/lib/python2.7/site-packages/zope.interface-4.1.1-py2.7-nspkg.pth
    Successfully installed twisted zope.interface
    Cleaning up...
    (virtualenv-demo)exarkun@top:/tmp$