Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error installing Twisted for Python

I tried installing twisted on an Ubuntu VM like this:

pip install twisted

It downloads and starts installation, but gets this error:

Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-SQhfJz/twisted/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ItHrMV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-SQhfJz/twisted

I'm not a real programmer, just a hobbyist, so this is way over my head. Googling it showed it needs python-dev and build-essential. I installed both of those, but installing twisted still got the same error as before.

Any thoughts?

like image 559
Seaver Avatar asked Jul 16 '15 14:07

Seaver


People also ask

Why is pip install not working in Python?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.

What is the use of twisted in Python?

Twisted is an open source asynchronous event-driven engine for network application development written entirely in Python and distributed under the MIT license. It allows you to create a SMTP, HTTP, proxy and ssh servers in a matter of minutes without the use of traditional threading models.


2 Answers

As a maintainer of Twisted, I'm sorry you're having a bad experience installing it. It's not your fault for being a hobbyist - it should just work :-).

It would be helpful if you could include more complete logs when reporting an installation error. Presumably there is some other stuff that pip tried to do. For example, when I tried to reproduce this error, I saw something similar, but right above it it said

error: could not create '/usr/local/lib/python2.7/dist-packages/twisted': Permission denied

which was the real bug. Is that what your installation attempt said? If so, then you have two options:

  1. You installed build-essential and python-dev. If you have the ability to apt-get install stuff, perhaps consider just apt-get install python-twisted? This will install an older version, but since it's supported by your operating system vendor it's almost guaranteed to work.
  2. You can install into a virtualenv. Installing into a virtualenv isolates packages from your system Python environment and reduces the number of things that can go wrong. One thing that can popularly go wrong is that pip install twisted by itself will try to install into your system's Python package manager, which is what the error I pasted above means. You can then do:

    $ sudo apt-get install python-virtualenv
    $ virtualenv my-fun-env
    $ source my-fun-env/bin/activate
    (my-fun-env)$ pip install twisted
    

    this will install Twisted inside a virtual environment only, which you can easily throw away and re-create to experiment with new versions of Twisted, so you don't have to make changes to your whole system to try things out.

  3. Don't do this: one popular way to "fix" this problem is to do sudo pip install .... This may superficially appear to work, but it also carries the risk of breaking your computer, and you really shouldn't do it unless you can easily reinstall your operating system to fix it. If another answerer suggests this, ignore them. Use one of my other two proposed fixes :).

like image 188
Glyph Avatar answered Oct 18 '22 15:10

Glyph


I have fixed it by installing the folowing packages

sudo apt-get install python-dev python-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
like image 20
anjaneyulubatta505 Avatar answered Oct 18 '22 16:10

anjaneyulubatta505